How to track which objects are alive and dead with events?

Hi,
I have an enemy wave manager, which spawns waves of enemies.
This wave manager needs to keep track of the enemies spawned and those who are still alive.

I tried using the OnDeath event to capture the objects death and stop tracking them... However, it appears than onDeath does not provide the gameobject which did the dying.

If I cannot use OnDeath, what would be the next best way to accomplish this?
I could use OnHealthDamage... but it seems silly to check if the object is dead or not after every damage when there is an event that already fires when it dies.
I may just be using OnDeath incorrectly.

While I am on the topic of events, I have a second question:
Is there an Opsive way/ pattern to have global events, like "player spawned", "game ended", and the like?
 
Well, this is the second time in as many days as I have put something in the wrong thread.
I am terribly sorry and embarrassed.
would a helpful mod be able to move this to "Ultimate Character Controller" Questions... >.<
 
I tried using the OnDeath event to capture the objects death and stop tracking them... However, it appears than onDeath does not provide the gameobject which did the dying.
You should use OnDeath - the GameObject that it gets called on is the object that dies. This is what I do with the Deathmatch AI Kit and it works really well.
 
Hrm, when I subscribe to the spawned object, it looks like this
C#:
//spawn new enemy
GameObject spawnedObject = Instantiate(enemyToSpawn, position, rotation);
//register to the enemy onDeath event
EventHandler.RegisterEvent<Vector3, Vector3, GameObject>(spawnedObject, "OnDeath", OnDeath)
and my onDeath method is defined as
Code:
private void OnDeath(Vector3 position, Vector3 force, GameObject attacker)

If I try
C#:
 EventHandler.RegisterEvent<GameObject, Vector3, Vector3, GameObject>(spawnedObject, "OnDeath", OnDeath)
and
C#:
private void OnDeath(GameObject gameObject, Vector3 position, Vector3 force, GameObject attacker)
I get an argument-parameter mismatch error.

Could I be provided some example syntax... I think there must be something I am missing.
 
You have the correct syntax on the top. The OnDeath event will be called on the spawnedObject GameObject so you know that's the object that died. OnDeath is not a global event. If you do a search within the project for OnDeath you'll see a few different examples of its use.
 
All the examples I found were of components listening for the OnDeath event of one other character. Is there no built in way to distinguish which character died if one component (in my case the enemy spawner) is listening to the OnDeath events of multiple characters (which which could be upwards of 20)?
 
Last edited:
All the examples I found were of components listening for the OnDeath event of one other character. Is there no built in way to distinguish which character died if one component (in my case the enemy spawner) is listening to the OnDeath events of all spawned characters (which which could be upwards of 20)?
No, the OnDeath event is not a global event so it must be attached to the GameObject that died. With that said, you could subclass the CharacterHealth component and create a new global event that includes the GameObject that died.
 
Top