Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Circle Sprite showing Square

Discussion in '2D' started by seanyappp, Feb 14, 2020.

  1. seanyappp

    seanyappp

    Joined:
    Aug 21, 2019
    Posts:
    2
    I’m trying to create a circle shaped sprite in Unity for my graph as a dot/coordinate.
    However it is showing as square! What did I do wrong?
    I simply right click in my materials folder then select Sprite, circle.
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    As far as I know the procedurally generated Unity sprite primatives can only be used with a SpriteRenderer. They will preview as a white square as an asset, but the sprite subobject should show the shape in the inspector.
     
    D12294 likes this.
  3. seanyappp

    seanyappp

    Joined:
    Aug 21, 2019
    Posts:
    2
    I started using the sprite in my script, using the following,
    Code (CSharp):
    1. [SerializeField] private Sprite circleSprite;
    2.  
    3. GameObject CreateCircle(Vector2 anchoredPosition)
    4.     {
    5.         GameObject gameObject = new GameObject("circle", typeof(Image));
    6.         gameObject.transform.SetParent(graphTransform, false);
    7.         gameObject.GetComponent<Image>().sprite = circleSprite;
    8.         RectTransform rectTransform = gameObject.GetComponent<RectTransform>();
    9.         rectTransform.anchoredPosition = anchoredPosition;
    10.         rectTransform.sizeDelta = new Vector2(1, 1);//size of circle
    11.         rectTransform.anchorMin = new Vector2(0, 0);
    12.         rectTransform.anchorMax = new Vector2(0, 0);
    13.         Debug.Log(gameObject);
    14.         return gameObject;
    15.     }
    However, when it is created during runtime, it is showing as a square. Regardless of the size i set it to using,
    rectTransform.sizeDelta = new Vector2(1, 1);//size of circle
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    You're using an Image component to display the sprite in the UI, but as I said I believe those it can only work when using a SpriteRenderer. You'll have to import your own circle sprite to use in the UI.
     
    D12294 likes this.