Best way to communicate to a lot of other actors something is dead?

I’m currently using delegates for this, but I find it cumbersome to have to unbind all the delegates before destroying an actor. Is there a better way to notify say 30 AI that my player is dead? The reason for this is I want the AI still active and to play an animation while enjoying the view of the players dead body, but I don’t want them trying to attack or anything so I notify the AI the player is dead. This works fine with delegates, but if the player kills an AI I have to unbind that delegate. Also do I have to unbind all these delegates? Will it not clean that up itself?

I guess I’m just asking if delegates is the right and most performant way to do this? I’ve read mention of blueprint interfaces, but I’m not understanding how they can help with this.

Would it be better/faster to just get all actors by class and call a function on them?

Edit: I also need to destroy all player projectiles on player death. Is it best to use a delegate for this as well or just get all actors by class and destroy them in the loop?

What I’d do, If you’re using behavior tree, is have a branch to the far left that checks if the player is dead, and aborts lower branches.

That doesn’t turn off things like timers though, which I am doing in my delegate event.

Well in general my advice for that is to avoid timers like the plague, but you could turn off the timers in that branch of the behavior tree.

Huh? There’s nothing wrong with timers. I don’t use tick.

At any rate it looks like having dozens of event dispatchers is perfectly fine based off the below topic.

Also looks like I don’t need to unbind all my delegates as GC will clear them out.

Sure, there’s nothing inherently wrong with timers, and there’s nothing inherently wrong with tick, but people often use both of them in place of doing things in response to something happening that they could be notified of.

I don’t see anything wrong with notifying every pawn in the game that the player died with a delegate, if they legit need to know about it. Considering that my next action would probably be to do something in the behavior tree, though, i’d just handle it in the behavior tree

2 Likes

I don’t know how that’d stack up performance wise. The behavior tree would be checking player status constantly where is a event dispatcher would only notify them once the player was dead. I would think constantly checking in the behavior tree would be worse performance.

Keep reading that interfaces can be used for this too, but I don’t understand how. I guess you can broadcast a message to all matching interfaces? Anyone have an example of how to do this? Would it be faster than binding to event dispatchers?

They probably mean using this as a filter:

image

From my own experience, from the performance point of view and from reading around, it seems that dispatchers are faster. There is a test somewhere in the forums comparing a 10k loop to 10k dispatcher calls. The loop is sluggish by comparison.

I doubt it’s measurable with 30 pawns but it probably would be if each had 100 projectiles flying around and we needed to interact with them, as well.

I also need to destroy all player projectiles on player death. Is it best to use a delegate for this as well or just get all actors by class and destroy them in the loop?

I’d also employ a delegate here, registered as soon as projectiles come to play. The GC creates clusters of actors before doing its magic so we, apparently, do not even need to stagger calls across frames.

Would it be better/faster to just get all actors by class and call a function on them?

Perhaps you could use a hybrid approach, do the above for the pawns (because unbinding can be a pain in the neck). But destroy the projectiles when invoking owning Pawn’s Destroy:

Hope I did not mix anything up.

2 Likes

Yeah I think delegates make the most sense here. For projectiles that’s basically what I’m doing except listening to a different event since the player death doesn’t mean the actor is destroyed. All seams to work fine so I’ll just go with this. Maybe I’m sometimes overthinking performance, but just want to do things right.

1 Like