📘Triggering Tasks Via Blueprints
The AI director makes decisions about what characters should be doing based on the state of the game world. There may be times when you want to override the director's decision making and force a specific task to play out at a specific moment in time. To accomplish this, you can use the Trigger Task node in blueprints.
In this example, we’ll demonstrate how to trigger a specific task in the Director when the player moves into a trigger volume. The level is a bar and the desired interaction is that if the player tries to move behind the bar, into the barkeep's space, the barkeep will shoo them away. The same technique can be used to trigger tasks in response to any game-side event.
Triggering Specific Content via Trigger Volume
Creating the Content
The content has a task called "Handle Player Behind Bar" which is meant to trigger if the player attempts to come around to the barkeep's side of the bar

Under task settings, Allow Director Initiation is toggled off. This ensures that the director will never proactively plan into this content and will rely on the game to decide when this task should be planned into.

Preparing the Level
To setup the level:
Add a TriggerBox to the map and drag it to the location you would like to trigger the task. In this case, the entrance to the bar area.

Add a cast spawner to the level that will spawn the barkeep NPC. Notice in the screenshot below that we've applied an optional gameplay tag to the barkeep. You'll use this tag later in this process to specify that the barkeep who scolds the player should be the specific barkeep that spawns at this spot. You can leave this field blank and allow the director to choose any valid barkeep if you desire.

This tag can be as generic or specific as you’d like, and as many spawned characters as you want can have it. If it’s a unique tag on a single character, then that means only that character will be a valid parameter binding value if the tag is used to make a parameter binding. If it’s a tag that’s on 50 characters, then any of those 50 in the level when the task is triggered could be used.
On the cast spawner, check that this cast is the Player Initial Cast.

Updating the Level Blueprint
With the level box selected, open the level blueprint.

Right click in the blueprint to bring up the menu to add a node to the blueprint. If you had the trigger box selected when you opened the level blueprint, you should see “Add Event for Trigger Box” at the top of the menu.

Click “Add On Actor Begin Overlap” to add the event. This event is emitted anytime an actor moves into the trigger volume. Overlapped Actor is the trigger box, and Other Actor is the actor that collided with it.

Drag a pin off Other Actor and select the Get Component by Class Node. This node allows you to check the Bitpart Agent Component which, if successful, tells you that the actor is a registered Bitpart entity. Search for, and select, the Bitpart Agent Component in the Component Class dropdown.

Next, you want to confirm if the Bitpart entity is the player. This is because, in this example, you want to trigger the event only when a player if you wanted it to trigger anytime any character went behind the bar you would exclude this player check. Drag a pin off return value and select the Is Player node.

Returning to the On Actor Begin Overlap node, drag off the Exec pin and add a ? Is Valid check. Connect the Get Component by Class Return Value to the Input Object on the ? Is Valid node.

Finally connect the Is Valid Exec to a Branch Node, connecting the Return Value from the Is Player node to the Condition of the Branch node. See the screenshot below:

Now that you know it was the player that entered the trigger box, you can trigger the task. Drag off the True path of the Branch node and add a
Trigger Tasknode. This is what asks the director to create a plan for the specified task. In the Task Name box, write the name of the task you want to trigger. Note that this is case sensitive and must exactly match the task name in Coppola.
Bindingsare values you can optionally supply theTrigger Tasknode to override the default parameter value providers in the content. The task you're triggering has the following parameters defined for it in Coppola:
Each of these is a parameter along with its default value provider -
barkeepandplayerwill have their values determined at runtime by querying the world state for entities with roles ofbarkeepand player. You can optionally override this by using theMake Parameter BindingandMake Player Parameter Bindingnodes in the level blueprint.
Click and Drag out of Bindings and select the Make Array node.
Click on the first pin and create a Make Player Parameter Binding node. Under Parameter Name write player (note: this must be an exact, case sensitive match to the parameter name in Coppola.)
Add a second pin to the Make Array box, click, drag and add a Make parameter Binding node. Under Parameter Name write barkeep. Again this must be an exact, case sensitive match to the parameter name in Coppola.
Make a new node off the tag field in Make Parameter Binding and choose Make Literal Gameplay Tag. Under the Value field, select the gameplay tag that you applied to the barkeep's spawner in the second step of preparing the level. This will ensure that it is that exact barkeep that will scold the player for coming behind the bar.
Finally, connect the trigger box’s Overlapped Actor output to the Reference Actor input on Trigger Task. The reference actor is used to determine what cast the task should be triggered for when the provided parameters are insufficient to make that determination. When the reference actor is used to find a cast, the nearest Bitpart entity in a cast to the reference actor is found, and that entity’s cast is used for planning. This is what your final blueprint should look like:

Now when you run the game, when the player steps into the trigger volume the Handle Player Behind Bar task will trigger.
Moving NPCs into New Casts via Blueprint
In the example above, the player and the NPC started in the same cast due to Player Initial Cast being set on the Barkeep's task spawner. In a large map you may have multiple trigger volumes setup to trigger tasks, involving NPCs in multiple casts. To ensure that those tasks trigger appropriately, you'll need to move the player into the same cast as the NPC involved in the task. You can do this by setting up the following logic in the blueprint:

If you are building off the example in the first part of this documentation, begin by disconnecting the Trigger Task node from the branch logic. You will reconnect it later.
As in the example Task Trigger example, we want to begin by getting the overlapping actor's Bitpart Agent Component.
Add the Get Component by Class node, and check the Bitpart Agent Component.
Add an Is Valid node, using the output of Get Component by Class to confirm the component is valid.
Add the Is Player node, connecting it to Get Component by Class to confirm that the actor is the player.
Finally connect the Is Valid Exec to a Branch Node, connecting the Return Value from the Is Player node to the Condition of the Branch node.
This is what your blueprint should look like at this stage:

Next we'll find the NPC whose cast we want the player to join when they overlap with the trigger box. We'll do this via the gameplay tag assigned on the cast spawner.

Add the Find Actor with Tag node to your blueprint. Drag off the Tag Pin and add a Make Literal Gameplay Tag Node. Set the value to match the Gameplay Tag assigned in the cast spawner. Remember that this returns the first actor found with the provided tag. If many actors have that tag assigned to them, only the first one will be returned from the node.
Add an is Valid note, connecting the return value of Find Actor with Tag to the Input Object and the Exec to the preceding branch node.
Drag off the Return Value pin of Find Actor with Tag and add Get Component by Class, checking the Bitpart Agent Component.
Add an Is Valid node, connecting the Return Value of Get Component by Class to the Inpit Object and the Exec to the previous Is Valid node. This section of the blueprint should look like this:

If all of the above succeeds, we can get the cast handle for the agent we found via the gameplay tag. A cast handle is a reference to a cast - in this case, the cast that the barkeep belongs to.
Add a branch node and connect to Is Valid in the preceding node.
Drag off the Condition Pin and add a Is Cast Handle Valid Node. Connecting the Return Value to the Condition on the Branch Node.
Drag off the Cast Pin of Is Cast Handle Valid and add a Get Cast Handle for Agent node, Connecting the Return Value to the Cast pin in Is Cast Handle Valid.
Connect the Agent Pin in Get Cast Handle for Agent to the Return Value in the Get Component by Class node where you checked the NPC's Bitpart agent component.
Add a Move Agent to Cast node to move the player to this agent's cast.
Connect the node to True in the preceding branch.
Connect the Cast to Join Pin to the Return Value of Get Cast Handle for Agent
Connect Agent to the first Get Component by Class node in this blueprint— the one where you checked the player's Bitpart Agent Component.

Connect a Trigger Task Node to Move Agent to Cast to have your task trigger after the player joins the agent's cast.
Turning Off Trigger Volume Collision
In the example above, you may want the bartender to yell at the player whenever they come behind the bar. However, in some scenarios it may be useful for a trigger volume to only trigger once. It's easy to do so by adding a single node to the existing blueprint.

Open your blueprint. Disconnect the last branch statement from the first blueprint function. You should be left with something that looks like this:

Right-click in the gray space and search for and select
Set Actor Enable Collision. Move the new node into the empty space you made. You may need to move some of the other nodes around for it to fit properly.

Minimize your blueprint window, and in your game level find the trigger volume for which you're building the blueprint. Select it. Go back to the blueprint, right-click in the gray space, and choose
Create a Reference to {your trigger volume's name}.If you previously toggled Context Sensitive off, be sure to turn it back on for this step.
A small node with the name of your trigger volume should appear. Connect the blue data output on this node to the Target output on the
Set Actor Enable Collisionnode.Lastly, connect the white execution pins on either side of the
Set Actor Enable Collisionnode. One should connect with the branch statement and the other to the blueprint fuction.Compile, save, and exit out of the blueprint. Now try it out for yourself!
Last updated