Triggering Sequences from Gameplay
Once you have created your cinematic sequence, you may want to have it called and played during gameplay as part of a cutscene. Perhaps a character walks into a room and you initiate a cutscene or maybe there is an ending cinematic you want to play when a character kills an enemy.
In this How-to we use 蓝图 - 可视化脚本 to tell a Level Sequence to play based on an in-game event. We also explore the Sequence Player options and how we can use them let our game know that the Level Sequence has ended, at which point we can fire of additional Blueprint script.
For this how-to, we are using the Blueprint Third Person Template project with a sample Sequence already created.
If the Level Sequence you want to play is not inside your level, Drag-and-drop it from the Content Browser into the level.
From the Modes panel, drag a Trigger into the level and adjust it based on your needs (we used a Box Trigger below).
When your player enters this trigger, we will tell our Level Sequence to start playing.
With the Trigger still selected, click the Blueprints button from the Main Toolbar then select Open Level Blueprint.
Right-click in the graph and under Collision, select Add On Actor Begin Overlap.
Return to the level and select your Level Sequence.
Click the Blueprints button from the Main Toolbar and Open Level Blueprint again.
Right-click and select Create a Reference to... your Level Sequence.
Above the Level Sequence we want to play is called CameraFlyBy.
Left-click and drag off the new node and add the Get Sequence Player node.
Off the Sequence Player node, add the Play node and connect as shown below.
If we were to play our game now, the sequence we created will play when the character enters the trigger.
With our current setup, our character can still freely move while our cinematic is playing. While we have managed to successfully playback our cinematic, there may be times where we want to lock our players in place while the cinematic is playing or to Set Hidden in Game so they do not appear.
Right-click in the Level Blueprint and add a Disable Input node.
If you have your Level Sequence still selected in the level, you may see two options (choose the one that is under Input by itself.
Connect the node following Play then drag off Player Controller and add a Get Player Controller node.
This will tell the Player Controller associated with your player to stop receiving input.
Drag off the Target pin of the Disable Input node and add a Get Player Character node.
We have disabled input when the sequence starts however we need to enable input once it is over.
Drag off the Sequencer Player node and add a Get Length node.
Right-click in the graph and add a Set Timer by Event node.
Connect the Set Timer by Event node following Disable Input and feed the Length into the Time pin.
This will allow us to call an event at the end of our Level Sequence.
Right-click in the graph and create a Custom Event called Sequence End.
Connect the bind pin to the Event pin on the Set Timer by Event node.
Whatever is connected to the Sequence End event will now get fired when the Level Sequence completes.
Add an Enable Input node and connect a Get Player Character and Get Player Controller node.
If we play now, our playable character will stop and not receive input while the Level Sequence is active. Once the sequence completes, the player is able to provide input to the character again.
With our current setup, our cinematic is not re-triggerable. If we want to re-trigger the sequence, we need to add one more node to our existing setup.
In the Level Blueprint, drag off the Sequence Player node and add a Set Playback Position node before the Play node.
With the Playback Position defaulting to start 0.0, the sequence will start from the beginning each time it is played.
Click the Play button to play in the editor.
We now have a cinematic sequence that is triggered from gameplay and locks the player in place. Our sequence can also be triggered multiple times and input is granted back to the player after the cinematic plays.
You can access other information or functions from the Sequencer Player node under the Cinematic section.