Message from class to level blueprint

I have an AI enemy, and I need to report it’s death to the level blueprint. How can I do this??? Thanks for any help :smiley:

Hi,

There is more than one way to do that. A simple one is to use EventDispatcher.
https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/EventDispatcher/index.html

Assuming the worst case scenario: you definitely need to report to the Level Blueprint for some reason, and the AI Enemy in question is spawned dynamically, so you cannot use any static reference to it anywhere.

If that is indeed the case (?) then you could do something like this:

  • Create an Event Dispatcher in one of your framework classes. I’ve used GameState in this example, so there’s a dispatcher called AIEnemyDied here, and it takes a Pawn input (this is just an example, add any inputs you need).

Your GameState-derived class should look like this:

  • Next up, in your Level BP, on Begin Play, you assign a custom event to the GameState’s AIEnemyDied dispatcher, and do whatever it is you want to do, when the event is called (I just have some debug printing here).

  • Finally, in your AI Enemy character blueprint, simply call the GameState’s AIEnemyDied dispatcher when the enemy instance in question has determined that it should die, like this:

26263-deadaitolbp_3.png

This will cause the custom AIEnemyDied_Event in the level blueprint to fire whenever an enemy calls that dispatcher. Just be careful with the references though! If you, like in this example, pass a reference to the killed pawn, it’s a good idea to make sure it isn’t actually deleted once you get to the level blueprint event, at least not if you’re going to use that reference for anything else moving forward. But like I mentioned above, what data you’re actually passing around isn’t important, as long as you get what you need. Dispatchers work fine without any inputs at all as well, if you only need the event itself without any additional data.

Oh, and if you use a GameState-derived class as I’ve done here, make sure that it’s set in the GameMode defaults as well, otherwise you’re not going to get any results.

I can’t get this to work because I can’t create a reference to the actor when I call the event dispatcher. This is because I spawn the bot after begin play through the level blueprint. What am I missing?

Then you are in the case of answer below. You spawn your character dynamically. You may want to set the Tag property for your character if you want to know who died in the Level BP logic.