- Home /
Instantiated Child objects don't appear in Game, but visible in scene
Hi, in my game project I'm facing an issue where the 'health bar' sprite object is appear on some objects and not on others. This is what I've done already...
I've attached my 'health bar' sprite to another sprite prefab as a child, configured the behavior and tested it. It worked fine (life goes down when attacked).
When I place the unit object prefab in the scene, everything renders properly and behaves as expected. You can see in the image below three different colored beetles facing upwards with health bars.
When I instantiate the prefab randomly (as my enemy) it also appears and behaves properly.
When I instantiate the prefab for the player on mouse click, the object is created as expected... but as you can see below, the 'health bar' is visible in the scene and not the game.
I've tried comparing Z values; changing rendering- layers, order, texture; camera settings; and the code for instantiating the prefabs for enemy and player are the same as well.
Not sure what else to try.
Answer by lipemon1 · Oct 18, 2017 at 10:14 PM
My first suggestion is to check the order number on your sprites.
If that don't solve your problem check your Camera. It can be not rendering everything. Check your Culling Mask option. Select " Everything" to do a quick test.
Also on your Camera component, check the values of your Clipping Planes. It can be cutting part of your objects.
Hope that solve your problem.
I've tested just about everything you've listed. Finally got it to work by changing the near clipping plane on the camera to 0.
It's weird that I've got this issue with the clipping plane on player objects and not for the enemy objects. But in any case, it was due to the clipping plane... I won't worry about how it became an issue for now.
Thanks for the suggestions!
Thanks! This was exactly my problem. "Clipping Panes Near" was 0.3. I set it to 0 and everything worked.
Answer by burak11581999 · Mar 14, 2021 at 07:57 PM
Guys, if that not solve your problem, you can change the camera projection from perspective to orthographic. That solved my problem.