Using Custom Events & Custom Structs

The Event Track can be used to call Custom Events and fire off Blueprint Script inside the Level Blueprint . Once the Custom Event is called, any script attached to it will also be executed and can be used for any number of scenarios based on your needs. When using the Event Track and calling a Custom Event, you can also pass through your own Custom Struct which can be used to update the variables contained within. This can be useful in situations where you want to update other variables during the playback of a level sequence.

In this example, we will use the Event Track to call a Custom Event with a Custom Struct that is used to move an object in the level when the sequence plays.

In the example above, when we press a key, the level sequence plays and our event to move the cube upwards is executed each time.

Steps

For this how-to, we are using the Blueprint Third Person Template project with Starter Content enabled.

  1. From the Content Browser under the Content/StarterContent/Shapes folder, drag any mesh into the level.

    EventTrack1.png

    Position the mesh anywhere inside the level.

  2. In the Details panel for your mesh, set the mesh to Movable.

    EventTrack1b.png

    This will allow us to move the mesh during gameplay.

  3. Click the Add New button, then under Blueprints, select the Structure option.

    EventTrack2.png

  4. Enter the name MyStruct, then open the asset and add a Vector variable called MoveCube.

    EventTrack3.png

    Naming of your variables is important here as these names will need to be used when you want to reference them later.

  5. Add a new Level Sequence from the Cinematics button called Master to the level, then inside Sequencer add an Event Track.

    EventTrack4.png

  6. Move the timeline to frame 5 and add a key, then Right-click the key and name the event LiftCube, assign MyStruct and set the Z value to 100.

    EventTrack5.png

    When we get to this keyframe in our sequence, we are going to move our mesh up by 100 units along the Z axis.

  7. Move the timeline to frame 10 and press the ] key to end the sequence at frame 10.

    EventTrack6.png

  8. Select your mesh that you added and the Level Sequence in the level, then click the Blueprints button from the toolbar and select Open Level Blueprint.

    EventTrack7.png

  9. In the Level Blueprint, Right-click and search for Reference then select Create Reference to 2 selected Actors.

    EventTrack8.png

  10. Right-click in the graph and add a 1 Keyboard Event, then drag off your Master Level Sequence and search for and add the Set Playback Position node.

    EventTrack9.png

    This will be used to reset our sequence whenever we start to play it before we actually issue a play function call.

  11. Drag off the Sequence Player node that is added and use the Play node and connect as shown below.

    EventTrack10.png

  12. Right-click in the graph and create a Custom Event called LiftCube.

    EventTrack11.png

    Your Custom Event name must be the same name that is specified under Event Name for your key in Sequencer or it will not get called.

  13. In the Details panel for the Custom Event, click the + button to add an input and name it MoveCube with the variable type of Vector.

    EventTrack12.png

    Your Input names must be the same names that are used in your Struct or the event will not get called. Also, the number of inputs must match the number of variables defined in your custom struct or the event will not get called. For example, if you struct has 2 variables in it, your Custom Event must have 2 inputs with the correct variable names and types.

  14. Drag off your mesh reference and search for and use the AddActorLocalOffset node.

    EventTrack13.png

  15. Connect the MoveCube vector pin to the Delta Location pin and the LiftCube executable to the AddActorLocalOffset node as shown below.

    EventTrack14.png

  16. Click the Play button from the Main Toolbar to play in the editor.

End Result

When playing in the editor, each time you press the 1 key, the cube will move up along the Z axis.

In this example we are not assigning a camera to view our cinematic from but instead are using Sequencer and Blueprint to perform scripted sequences. In your projects, an Event Track with a Custom Event and Custom Struct can be used to update player information during a cutscene (such as the player receiving a health increase, new weapon, or other gameplay related effects of your choosing).

Tags