Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question NPC game objects disappear from view in play mode

Discussion in 'Editor & General Support' started by mattCap42, Dec 16, 2022.

  1. mattCap42

    mattCap42

    Joined:
    Jul 25, 2022
    Posts:
    7
    I have NPC characters that are contained within a parent game object. in play mode some of them seemingly become invisible. sometimes switching to scene and back to game tab makes them show up other times it doesn't.

    I have looked at camera clipping planes, and various occlusion settings, I have tried update when off screen, and turning off dynamic occlusion. after trying all of these things, I realized that the child objects are actually still in the game, but in strange locations far away from the parent objects (and everything else in the scene). after realizing this I tried parent constraints to no avail.

    I have gone over and over my code and cannot find anything that would cause the child to move away from the parent other than the death/ragdoll animation, but that is only triggered when health reaches 0 and this is happening to NPCs that are still actively fighting and damaging enemies or even just recently spawned and haven't even entered combat

    If anyone has any thoughts on where I may look for the issue/solution I would be extremely grateful. This is a game killing bug and I'm at my wits end trying to understand the cause not to mention how to fix it.
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,455
    Put debug.logs in code to see what runs when and what values are in the script.
    Then you see where something goes wrong
     
  3. mattCap42

    mattCap42

    Joined:
    Jul 25, 2022
    Posts:
    7
    Thanks for the suggestion. I have done that and I can see the Die() method which contains the only code that moves the child object is not being called. The only other thing that moves Npc objects is the Navmesh agent but that is on the parent, so I'm not sure if that could cause the child to move away from the parent.