Checking if enemy is dead every frame

I was wondering about the if (health.IsDead()) in Update. Checking if the enemies or the player is dead every frame seems unnecessary since the state rarely changes. If there are many enemies, might this affect performance, or is the effect negligible? How does this solution compare to just turning off the AIController script?

I actually had a to chuckle a bit there… in one of the Police Squad movies, a call comes through to interogation, and we hear the officer reply to the call “Well let me know if his condition changes”. He then turns to the person being interogated and says “so and so is dead”…

Of course, in games, these sorts of things often do change.

The solution, of course, is to deactivate the NavMeshAgent as a response to the OnDie event, and in the event your game includes characters that get back up after you kill them (hey, just because Sam and Rick didn’t make a Zombie game, doesn’t mean you can’t!), you could create an event OnRessurect that turns the NavMeshAgent back on (and resets the Animator).

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms