|
When an Event Dispatcher is called, any Blueprints that implement and have Events bound to the Event Dispatcher will also execute when the Event Dispatcher is called. In other words, whenever the Event Dispatcher is called, any Events that are bound to it are also called allowing you to execute multiple Events at once from a single source.
This page will show you how to set up an Event Dispatcher and Bind an Event to the Event Dispatcher.
For this example we will allow the player to press a key which will cause a fire particle effect to spawn inside of a bush.
For this guide we are using the Blueprint Third Person template with Starter Content enabled.
In the Content Browser, under the Content/ThirdPersonBP/Blueprints folder, open the ThirdPersonCharacter Blueprint.
Under the My Blueprint window, click the Add Event Dispatcher button and name it StartFire.
Right-click in the graph window and add an F Key Event.
Drag the StartFire Event Dispatcher into the graph and select Call.
Connect the F Key Event to the Call StartFire Event Dispatcher.
Whenever the F key is pressed, any Blueprints that have an Event bound to this Event Dispatcher will also be executed.
Compile and Save then close the Blueprint.
In the Content Browser under Content/StarterContent/Props, drag the SM_Bush into the level.
From the Main Toolbar, click the Blueprints button then select Open Level Blueprint.
Right-click inside the graph and select the Create a Reference to SM_Bush node.
Here we are getting a reference to the SM_Bush inside our level.
Don't see the node listed above Select the SM_Bush inside your level then try again.
Right-click in the graph and add an Event Begin Play and Get Player Character node.
Off the Get Player Character node, search for and add the Cast To ThirdPersonCharacter node.
This will allow us to access the Events, Functions, Variables or Properties inside the ThirdPersonCharacter Blueprint.
Please see the Casting documentation for more information regarding Blueprint Cast Nodes.
Off the As Third Person Character pin, search for and use the Assign Start Fire node.
This will create two new nodes, a Bind Event node and a Custom Event. Whenever the Event Dispatcher is called inside our Character Blueprint, since we are binding that event, the Custom Event and anything connected to it will also be executed. Any Blueprints that have Events bound to the Event Dispatcher will also be executed.
Off the Custom Event, add a Spawn Actor from Class node (with Class set to Blueprint_Effect_Fire).
Drag off the SM_Bush to Get Actor Transform and use that as the Spawn Transform for the Spawn Actor node.
Once all nodes are connected, your graph should look similar to above.
Click Compile, close the Level Blueprint, then click Play to play in the editor.
When you press the F key, the fire effect will spawn inside the bush.
For more information on working with Event Dispatcher and sample use cases, refer to the Related Topics below.
相关页面
事件调度器
蓝图交互的用法
蓝图用户指南
|
|