Enabling communication between assets

With our patrol points established, we can transition to building the intelligence of our enemy. To begin, we are going to give our Blackboard the ability to store information about the location of a patrol point. Open EnemyBlackboard from the Content Browser. Click on New Key and select Object as the Key Type. Click on the expansion arrow next to
Key Type and change the Base Class to Actor with the dropdown. Name this new object key PatrolPoint, as shown in the following screenshot:

Now that we have a PatrolPoint key set up within Blackboard, we need to set the value of that key within Blackboard to the actual Patrolpoint object in the world. We can do this from the EnemyCharacter Blueprint, so open the character Blueprint now.

When you open a Blueprint that does not have any scripts or variables, a simple Editor is displayed only to edit the default values. You need to click on the Open Full Blueprint Editor link at the top to see the usual layout.

We want to create a sequence that starts when the enemy character is created and then grabs EnemyBlackboard. The Set Value as Object node will then set the key value, called PatrolPoint, inside Blackboard to the value contained within a variable we will create for the character Blueprint representing the enemy's Current Patrol Point target, as shown in the following screenshot:

First, we want to create variables that will store our two patrol point objects. Add a new variable from the My Blueprint panel and call it PatrolPoint1. Set Variable Type to Actor and check the Instance Editable attribute. Now, right-click on the variable and duplicate it. Name this duplicate PatrolPoint2. Finally, duplicate the Actor variable a third time and name this variable CurrentPatrolPoint. We will change the patrol point stored in this variable each time we want to move the enemy to a new location.

With the three variables created, we want to use the Event BeginPlay node, which is already in Event Graph. Add a Get Blackboard node, drag a wire from the Target input pin, and search for and select GET Reference to Self to attach a Self node to the pin. Now, drag a wire from the Return Value pin and attach it to a Set Value as Object node. Connect this node's input execution pin to the Event Begin Play node.

Returning to the Set Value as Object node, drag a wire from the Key Name input and attach it to a Make Literal Name node. Set the Value field within this node to a patrol point so that it references the key we created inside Blackboard. Finally, drag the Current Patrol Point variable to Event Graph and select GET. Connect the GET Current Patrol Point node to the Object Value input pin of Set Value as Object. Select all these nodes and create a comment for yourself that describes the functionality.

Next, we want to create a series of nodes that will swap the patrol point the enemy is moving toward each time they successfully reach one of their two patrol points. To do this, we will create two branches that will trigger off the detection of a collider overlap, as shown in the following screenshot:

Begin by creating an Event ActorBeginOverlap node. Attach this node to a Branch node. Drag a wire from the Condition input of the Branch node onto an Equal (Object) node. This node evaluates whether the two objects attached to the two inputs of the node are identical to one another. In our case, we want to evaluate whether the object being overlapped by the enemy is the same object that is attached to the Patrol Point 1 variable.

Drag a wire from the Other Actor output pin of the Event ActorBeginOverlap node and attach it to the top input pin of the Equal (Object) node. Now, drag the Patrol Point 1 variable onto the graph and attach a GET Patrol Point 1 node to the bottom input pin of the Equal (Object) node. If these two objects are equal, then we will change the Current Patrol Point variable to Patrol Point 2. From the True output pin of the Branch node, attach a wire to a SET Current Patrol Point node and attach a GET Patrol Point 2 node to its input pin.

Next, we need to create a second branch series to test against the other patrol point. Drag a wire from the False output pin of the Branch node and attach it to a second Branch node. Attach the Condition input pin of this new Branch node to a new Equal (Object) node. Connect the top input pin of the Equal (Object) node to the Other Actor output pin of the Event ActorBeginOverlap node.

Drag the second patrol point variable onto the graph and attach a GET Patrol Point 2 node to the bottom input pin of Equal (Object). Now, attach the True output pin of the second Branch node to a new SET Current Patrol Point node. Then, attach a GET Patrol Point 1 node to the input pin of SET Current Patrol Point.

Finally, attach the output execution pins of both SET Current Patrol Point nodes to the input execution pin of the Set Value as Object node, which is in the other block of Blueprint nodes we used to set Blackboard Key. This final step is important to ensure that the updated Current Patrol Point value gets sent to the Blackboard every time the value of the variable changes.

This finishes the work we have inside EnemyCharacter. Next, we need to go to the AI Controller and instruct it to run the Behavior Tree that we'll set up. Return to Content Browser and open EnemyController.

In the Event Graph of EnemyController Blueprint, add an Event BeginPlay node. Connect this node to a Run Behavior Tree node. Finally, set the BTAsset input parameter inside this node to EnemyBehavior. That's all there is to do with the controller, as shown in the following screenshot:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset