Skip to content

🐉 Dragon Spawn

In this little example, we’re going to register our players for an event that fires when a Dragon spawns!

Right click in your content browser and navigate to AES -> Event.

Create AES Event context menu

This will generate a custom AES Event asset.

AES Event asset created

Open the AES_DragonSpawned event and add any properties as you normally would. In our example we’re going to add Level and Location.

We make sure any properties that we want to be exposed when this event is generated are set to Instance Editable and Expose on Spawn.

Add payload properties

Generate a unique Identity for any actor, component, system or object that may send or receive events. In our case, we’re generating an Identity for our Dragon Slayer player pawn!

Generate identity for player

Now that we’ve generated an Identity, we can use it to talk to the Event Manager.

Here we register for a Broadcast event by passing in a Registration that consists of the AES Event that we want to listen for and the delegate we want to call when the event happens. In our case the event is AES_DragonSpawned and the callback is our OnDragonSpawned custom event.

Register for broadcast event

When the event is generated and this delegate gets called, we get a generic AES Event Payload. In order for us to get data from a specific event type, we can use 1 of 2 methods:

If this delegate (our On Dragon Spawned custom event) is only ever going to be used for this specific AES_DragonSpawned event, we can use a simple cast to get the data we need.

Cast method for event payload
2) Switch on Event Method (Multi-Use Delegate)
Section titled “2) Switch on Event Method (Multi-Use Delegate)”

If we want this delegate to handle multiple events, we should rename it to something more generic like Handle Events and then we can use our custom Switch on Event node to get our data.

Switch on Event node

Selecting the Switch on Event node will show some settings in the detail panel. We can hide the Default pin in this case and add our AES_DragonSpawned event. We keep the Has Cast Pins because we want it to auto-cast our event type so we can easily grab the data from our AES_DragonSpawned event.

Switch on Event node details

In our Dragon class, on Begin Play we generate an Identity for the dragon and then we call Generate Event.

Generate event in dragon class

As soon as the AES_DragonSpawned event is selected, any Instance Editable and Expose on Spawn properties will automatically generate pins allowing us to set the values before the event is broadcasted.

Event payload pins

This spawning would obviously be handled by whatever system you have in place that’s responsible for spawning the dragon.

For demo purposes, in our BP_DragonSlayer character we add a simple Print String so we can see our event when it gets called.

Spawn blueprint print string

Since we’re playing as a Server, we can just hardcode a keypress to spawn a BP_Dragon on demand.

Key press spawns dragon

Now when we press G we’ll see our BP_Dragon is being spawned and on Begin Play since its generating a random level our AES_DragonSpawned event gets called with the Level and Location payload that we passed in earlier and our BP_DragonSlayer character is hearing the event and seeing the data correctly!

Event output log

Now we say GG in the chat as all of these dragons head to the nearest town for a good ol’ barbecue! 🥩🔥