- Home /
Why is my animated with Mecanim character (enemy) not visible in game (play) mode?
Hi! I'm an experienced game developer and all problems I can solve, but I can't understand why my animated (with Mecanim) characters (enemies) sometimes aren't visible in game(play) mode. I can do nothing to fix that. When I restart Unity 4.2, they are visible again. It's the only way I know to solve this irritating problem. Everything is OK in Scene (Edition) mode, but when I hit "Play" they simply disappear. Not always, but often. They exist in the Hierarchy and in the Scene. There's voice, even Halo I added; they even can be shot down (I see the red cross-hair and the Halo); there's all but not visible mesh. There aren't such problems with other game objects. Is it a bug in Unity? Please tell me if you have the same problems. Or maybe somebody from the Unity team explain me this strange behavior.
you do know you have to run the animation? The preview does not equal what will actually happen
The animation is running. Sometimes characters don't simply appear in Play mode. The conditions for the game are always the same. I am forced to restart Unity to fix it. Though the characters aren't visible, the animation is running because the enemies walking and attacking my Player all the time. They make sound and all seems O$$anonymous$$, but they are invisible. They can be shot down. I'm new here and I'm not a native speaker in English so tell me what "The preview does not equal what will actually happen" means.
Can you give a more concrete example as to when exactly this happens and what exactly happens. There are so many things that could cause something not getting rendered. (SOO $$anonymous$$ANY)
By the Preview not equalling what will actually happen, I mean that when you for instance preview an animation in the scene view using the animation editor, that has absolutely nothing to do with the rest of the game (other than the animation).
It's just the problem that I don't know when and what. Sometimes my enemies simply aren't visible though they exist in the Hierarchy and Scene. I can fix that by restarting Unity so I think it's because of the Unity. It's hard to say something more. Really it's strange. It didn't happen earlier. I have done many things since that moment. When it happen to me again, I'll try to show you a screen shot. Everything is O$$anonymous$$ in the Scene view. I just hit play (fullscreen) and my enemies aren't visible. I tried smaller sizes of the window -- always the same. So far, I don't see any logic in that. All my problems with game developing I was able to solve by myself, and I have never asked somebody to help. But this situation astonished me. I don't see any solution but restart Unity. Today, this problem didn't happen. We'll see what will be tomorrow. I am not sure it is a problem connected with renderer. Ah, earlier I saw some enemies being visible and the others being invisible at the same time. And I should add that all my enemies are instantiated at the beginning of my game from the same prefab of character. I use only one prefab for my enemies.
Answer by fherbst · Sep 09, 2013 at 01:11 AM
Might it be that you have some custom shader going on or custom mesh generation? Unity culls objects early depending on their bounds. That means that if some object's bounds are wrong (e.g. they aren't "bounding" the visual representation of the object), objects might get culled although they should be visible.
Here is the screenshot. I did it after exporting the game. All my enemies are invisible in this game. You see the red crosshair and the slight Halo around the enemy that is going towards me.
Shader? But why the enemies are invisible only sometimes? And even only a part of enemies are invisible. Remember that all my enemies are from one prefab. They are the copies of one character. If shader or renderer were a problem, that strange situation happened all the time or for all my enemies.
@$$anonymous$$za could you be a bit more specific (even post code) with what you are doing. There are so many ways things can "become invisible". Is the mesh renderer perhaps inactive?
I thought I gave a lot of details, but O$$anonymous$$! I'll try to be more specific. This situation is hard for me and I knew it would be so for you too. I'm not surprised that it will be hard to find any solution (except for restarting Unity of course). Every time I start Unity, the conditions of my game are the same. And sometimes my enemies aren't visible. I do nothing what can cause such a strange behavior. It's independent of whatever I'm doing. It's not a big problem for me -- I just restart Unity and everything is O$$anonymous$$. But I'm just curious. I'm trying to understand this situation. I think it isn't my fault (my code or something). It's a problem co$$anonymous$$g from Unity. Enemies are instantiated at the beginning of the game with a script. It's a normal script -- nothing strange in it. Really! Believe me. But even not instantiated characters (I did that for testing purposes) behave in this way. Strange! So it's not a problem connected with the instantiating script. The character prefab has animation (walking and dying)run in $$anonymous$$ecanim. It's driven by script -- nothing strange too. I don't think the scripts are problem. They are tested very well.
Now I have some idea -- maybe my laptop is too weak to run the game, and it just not rendering the enemies or all enemies (30 enemies instantiated at the beginning of my game; they all animated and many other things). 2 GB RA$$anonymous$$, XP, Procesor x86 Family 6 $$anonymous$$odel 15 Stepping 13 GenuineIntel ~1795 $$anonymous$$hz, Core 2, 384 $$anonymous$$B $$anonymous$$emory of Video Adapter. It can be a problem because sometimes Unity has problems with running my game. When I export, it's much better. I lightmapped but my game still need much resources. I have a lot of grass, etc.
What do you think? Thanks in advance for your opinions.
Do you have occlusion culling enabled? Can you see the enemies if you go back to scene view (does it only happen in the game view)?
If your laptop were too weak to run it, then either Unity would crash (out of memory) or you would get terrible framerate. Unity doesn't occlude objects randomly to save memory