Instantiated child prefab is invisible

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.

With 2D components, you also need to check the Order in Layer it is casted to. If it’s behind your ground, you won’t see it.
3577727--289026--Screen Shot 2018-07-27 at 14.06.10.png

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

Hey sorry for the late reply,

Did you already solve your problem ?

If not the problem might lie in the way you instantiate the GameObject. Quaternion.identity will reset all rotations of the parent prefab to zero.

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

Of course,

The easy way is to use Quaternion.Euler(a, b, c) where a, b, c are in Degrees (the angles you put in your inspector).

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?

If your Asset’s Texture Type is a Sprite(2D and UI) . You can use the “RawImage” component with:

RawImage rawImage; Spite yourSprite;

rawImage.texture = yourSprite.texture;

It also work if you want to display videos. You can’t change the “Texture” component of an image as it is “readOnly”.

So if you want to display a Sprite in an Image, use “RawImage”.

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.

1 Like

This may be a bit late but I’ll put this here for others who come across this thread

if the z position of the spawn point and the player are not both equal to 0 then it will spawn invisible

hope this fixes your problem :slight_smile:

6 Likes

Thanks. This worked for me.

check the z axis

I had this same problem and this fixed it, thank you very much!

thanks alot, this really helped me

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?