Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Unity UI Prefab UI Image is invisible when Instantiate

Discussion in 'UGUI & TextMesh Pro' started by Diegorinio, Feb 26, 2024.

  1. Diegorinio

    Diegorinio

    Joined:
    Nov 29, 2018
    Posts:
    5
    I want to generate grid on canvas, but i don't want fill canvas so i spawn objects inside Panel, but even without Panel and adding Images to Canvas images are still invisible
    I have Canvas which have Panel as children which contains my script to spawn and GridLayoutGroup, I want to Instantiate prefab which contains UI Image but when making it by script my Images are invisible

    I have this script attached to my Panel
    Code (CSharp):
    1. for(int x =0;x<width;x++){
    2.             for(int y=0;y<height;y++){
    3.                 GameObject newTile = Instantiate(_tilePreset,gameObject.transform.position,Quaternion.identity);
    4.  
    5.                 gridMapGameObjects[x,y]=newTile;
    6.                 newTile.transform.SetParent(gameObject.transform);
    7.             }
    8.         }
    It only works when adding manually every image to my Panel.
    It worked with SpriteRenderer but sprites are over UI elements
     
  2. Diegorinio

    Diegorinio

    Joined:
    Nov 29, 2018
    Posts:
    5
    Okay nvm i just figured out that scale of Tile on RectTransform was too big