Hi!
I have a problem with 2D Unity project. When I instantiate prefabs in my canvas, objects are created, I am able to click on them, but they’re invisible in the Scene and Game panels. I tried to change Z-positon, but it still doesn’t work. Here is my script, which I use on the parent of the prefabs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlockSpawner : MonoBehaviour
{
public Transform[] spawnPoints;
public GameObject blockPrefab;
public void Start ()
{
Instantiate (blockPrefab, spawnPoints[i].position, Quaternion.identity);
}
}
How can I make the prefabs is visible? Thanks for any help.
The order in layer of the parent prefab is 3 and the child is 5 so that should be OK. I changed the sorting layer of both the parent and child prefab but the child is still invisble. When I drag the prefab into the scene it’s displayed correctly. The problem isn’t in layers
Oh, no, I didn’t solve this problem.
Could you tell me, how I should instantiate my prefabs without using Quaternion.identity? If it’s possible of course
Oh, there are appeared new conditions. So, prefabs are invisible, if they have Image Component. If I use Sprite Renderer instead Image or prefab is a Сube for example - it’s visible. But I need to use Image Component. I really don’t know what the problem is. So, have you any idea, how to make the Image Component is visible?
I know this is late but I had the same exact problem and it was really frustrating. I’m surprised no one answered this question but this is how I solved it:
I put the spawn point under a sprite. You can leave the sprite field in the sprite renderer empty and it looks like a regular empty 2d point.
I was just trying random shit and have no idea why this works.
Hi, I am late to this post, but none of these tricks works for me. My prefab is a UI button with an image and no text. When I instantiate it does not show up in game view. In scene view it shows up as an empty rectangle with green borders. Any thoughts on how to instantiate my game object so I see the image?