Smart Objects Quick Start

This guide shows how to create and use Smart Objects with an AI Agent.

Choose your operating system:

Windows

macOS

Linux

Overview

Smart Objects are objects placed in a Level that AI Agents and players can interact with. These objects contain all the information needed for those interactions.

At a high level, Smart Objects represent a set of activities in the Level that can be used through a reservation system. This system keeps track of all the Smart Objects in the Level and allows an AI Agent to "reserve" a Smart Object so no other Agent can use it until the Smart Object becomes available again.

Goals

In this Quick Start guide, you will learn how to create and use Smart Objects with an AI Agent.

Objectives

  • Create the AI Gameplay Behavior and Behavior Definition that the AI Agent can use when it reaches a Smart Object.

  • Create a Smart Object that uses the Behavior Definition to play an animation montage.

  • Create simple AI behavior with a Behavior Tree and Behavior Tree Tasks.

  • Create the AI Agent that can search for and use Smart Objects in the level.

1 - Required Setup

  1. Create a new Blueprint project based on the Third Person template.

  2. From the main menu, go to Settings > Plugins to open the Plugins window.

    Open the Plugins window

  1. Go to the Gameplay section and enable the Smart Objects and AI Behaviors plugins. Restart the editor if prompted.

    Enable the Smart Objects plugin

    Enable the AI Behaviors plugin

Section Results

In this section, you created a new project and enabled the Smart Objects and AI Behaviors plugins. You are now ready to create the AI Gameplay Behavior for your AI Agent.

2 - Creating the AI Gameplay Behavior

In this section, you will create the Gameplay Behavior and Gameplay Config Blueprints that define what your Agent will do when it reaches a Smart Object Slot.

  1. In the Content Browser, right-click and select Blueprint Class from the Create Basic Asset section.

    Create a new Blueprint Class

  1. In the Pick Parent Class window, expand the All Classes section, then search for and select Gameplay Behavior. Click Select and name the new Asset BP_SO_Behavior_PlayMontage.

    Select the Gameplay Behavior class

  2. Create a new Blueprint class, then search for and select Gameplay Behavior Config. Click Select and name the new Asset BP_SO_BehaviorConfig.

    Select the Gameplay Behavior Config class

  3. In the Content Browser, double-click BP_SO_BehaviorConfig to open it. Go to the Details panel and click the Behavior Class dropdown. Select BP_SO_Behavior_PlayMontage. Compile and save the Blueprint.

    Add the BP_SO_Behavior_PlayMontage to the Behavior Class

  4. In the Content Browser, double-click BP_SO_Behavior_PlayMontage to open it. Click the Override dropdown next to Functions and select OnTriggeredCharacter.

    Override the OnTriggeredCharacter function

  5. Right-click the Avatar pin of the Event OnTriggeredCharacter node and select Promote to Variable.

    Right-click the Avatar pin of the Event OnTriggeredCharacter node and select Promote to Variable

  6. Drag the Avatar variable to the Event Graph and select Get Avatar. Drag from the Avatar node, then search for and select Get Component by Class.

    Search for and select Get Component by Class

  7. Click the Component Class dropdown, then search for and select Skeletal Mesh Component.

    Add the Skeletal Mesh component

  8. Right-click in the Event Graph, then search for and select Play Montage.

    1. Connect the Return Value pin of the Get Component by Class node to the In Skeletal Mesh Component pin of the Play Montage node.

    2. Connect the Set Avatar node to the Play Montage node.

    Add a Play Montage node

    Connect the Play Montage node to the Set Avatar node

  9. Click the Montage to Play dropdown on the Play Montage node. Select an animation montage from the list.

    Select an animation montage to play

    If you don't have animations available, you can get free animation asset packs from the Unreal Engine Marketplace, such as the Animation Starter pack.

  1. Drag the Avatar variable to the Event Graph and select Get Avatar. Drag from the Avatar node, then search for and select End Behavior.

    Add the End Behavior node

  2. Connect the On Completed and On Interrupted pins from the Play Montage node to the End Behavior node.

    Connect On Completed and On Interrupted to the End Behavior node

  3. Compile and save the Blueprint.

    This example uses the Play Montage node, as opposed to the Play Anim Montage node to use the On Completed and On Interrupted pins to end the behavior. This ensures the Smart Object remains occupied until the animation finishes playing.

Section Results

In this section, you created the Gameplay Behavior and Gameplay Config Blueprints that the Agent will use to play an animation montage once it reaches a Smart Object Slot. You can now create the Behavior Definition that will be used by the Smart Object.

3 - Creating the Smart Object Definition Data Asset

In this section, you will create the SmartObject Definition Data Asset that will define the behavior for each Slot of the Smart Object.

  1. In the Content Browser, right-click and select Miscellaneous > Data Asset.

    1. In the Pick Class for Data Asset Instance window, search for and select Smart Object Definition.

    2. Click Select to create the Asset and name it SO_Definition_PlayMontage.

    Select Miscellaneous - Data Asset

    Select the Smart Object Definition

  2. In the Content Browser, double-click SO_Definition_PlayMontage to open it. Scroll down to the Smart Object section and click the Add (+) button next to Slots to add a new Slot. This is the Slot that will be used by the AI Agent when performing the behavior.

    Click the Add (+) button next to Slots** **to add a new Slot

  3. Click the Add (+) button next to Default Behavior Definitions and select Smart Object Gameplay Behavior Definition for Index 0. Click the Gameplay Behavior Config dropdown and select BP_SO_BehaviorConfig.

    Add a new Default Behavior Definition

  4. Save and close the Blueprint.

Section Results

In this section, you created the SmartObject Definition Data Asset that defines each Slot of the Smart Object and its default behavior definition.

4 - Creating a Smart Object

In this section, you will create a Smart Object that can be found and used by an Agent in the level.

  1. In the Content Browser, right-click and select Blueprint Class from the Create Basic Asset section.

    Create a new Blueprint Class

  2. In the Pick Parent Class window, click the Actor class button to create the asset. Name the new Asset BP_SO_RunBT.

    Select the Actor class

  3. In the Content Browser, double-click BP_SO_RunBT to open it. Go to the Components window and click the + Add button. Search for and select Smart Object.

    Select the SOComponent component

  4. With the SmartObject component selected, go to the Details panel and scroll down to the Smart Object section. Click the Definition Asset dropdown and select SO_Definition_PlayMontage.

    Add the Definition Asset

  5. Compile and save the Blueprint.

Section Results

In this section, you created a Smart Object and added the Behavior Definition that defines the default behavior of its Slot.

5 - Creating the Behavior Tree for the AI Agent

In this section, you will create the necessary behavior for the AI Agent to search for and use Smart Objects in the Level. You will use a simple Behavior Tree and two custom Behavior Tree Tasks to accomplish this.

Creating the Behavior Tree and Blackboard

  1. In the Content Browser, right-click and select AI > Blackboard. Name the Blackboard BB_SO_Agent.

    Create a Blackboard

  2. Double-click BB_SO_Agent to open it. Click the New Key dropdown and select SmartObject Claim Handle. Name the key ClaimHandle. Save and close the Blackboard.

    Add a SmartObject Claim Handle

  3. In the Content Browser, right-click and select AI > Behavior Tree. Name the Behavior Tree BT_SO_Agent.

    Create a Behavior Tree

Creating the Behavior Tree Tasks

Finding Smart Objects

  1. In the Content Browser, right-click and select Blueprint Class from the Create Basic Asset section.

    Create a new Blueprint Class

  2. In the All Classes section, search for and select BT Task Blueprint Base, then click Select. Name the Blueprint BTT_FindSmartObject.

    Search for and select BT Task Blueprint Base, then click Select

  3. In the Content Browser, right-click BTT_FindSmartObject and select Duplicate. Name the new Blueprint BTT_UseSmartObject.

    Duplicate BTT_FindSmartObject

  4. In the Content Browser, double-click BTT_FindSmartObject to open it. In the Event Graph, right-click, then search for and select Event Receive Execute AI.

    Add the Event Receive Execute AI node

  5. Drag from the Owner Controller pin of the Event Receive Execute AI node, then search for and select Get Blackboard.

    1. Right-click the Return Value pin of the Get Blackboard node and select Promote to Variable. Name the variable Blackboard.

    2. Connect the Event Receive Execute AI node to the Set Blackboard node.

    Add the Get Blackboard node

    Connect the Set Blackboard node to the Event Receive Execute AI node

  6. Drag from the Controlled Pawn pin of the Event Receive Execute AI node, then search for and select Get Actor Location.

    1. Drag from the Return Value of the Get Actor Location node, then search for and select Subtract.

    2. Drag from the Return Value of the Get Actor Location node, then search for and select Add.

    3. Set the X, Y, and Z values of both nodes to 2000. This creates a search box of 4000 x 4000 units, or 40 x 40 meters around the Agent.

    Add the Get Actor Location node

    Add Subtract and Add nodes

  7. In the Event Graph, right-click then search for and select Make Box.

    1. Connect the Subtract node to the Min pin of the Make Box node.

    2. Connect the Add node to the Max pin of the Make Box node.

    Add a Make Box node

    Connect the Make Box node

  8. In the Event Graph, right-click then search for and select Get Smart Object Subsystem.

    1. Drag from the Smart Object Subsystem node, then search for and select Find Smart Objects.

    2. Drag from the Request pin of the Find Smart Objects node and select Make SmartObjectRequest.

    Add a Get Smart Object Subsystem node

    Add a Find Smart Objects node

    Select Make SmartObjectRequest

  9. Connect the Return Value pin of the Make Box node to the Query Box pin of the Make SmartObjectRequest node.

    1. Drag from the Filter pin of the Make SmartObjectRequest node and select Make SmartObjectRequestFilter.

    2. Click the Behavior Definition Class dropdown on the Make SmartObjectRequestFilter node and select SmartObjectGameplayBehaviorDefinition.

    3. Connect the Set Blackboard node to the Find Smart Objects node.

    Connect the Return Value pin of the Make Box node to the Query Box pin of the Make SmartObjectRequest node

    Select SmartObjectGameplayBehaviorDefinition from the dropdown

  10. This is what the Blueprint looks like so far.

    The Blueprint so far

  11. Right-click the Out Results pin of the Find Smart Objects node and select Promote to Variable.

    1. Drag from the pin of the Out Results node, then search for and select Is Valid Index.

    2. Drag from the Is Valid Index node, then search for and select Branch. Connect the Out Results node to the Branch node.

    Right-click the Out Results pin of the Find Smart Objects node and select Promote to Variable

    Select Is Valid Index

    Select Is Valid Index

  12. Drag from the False pin of the Branch node, then search for and select Finish Execute. The Out Results will be invalid if no nearby Smart Objects match the search criteria.

    Drag from the False pin of the Branch node, then search for and select Finish Execute

  13. Create a Smart Object Subsystem node in the Event Graph. Drag from the node, then search for and select Claim.

    1. Connect the True pin of the Branch node to the Claim node.

    2. Drag the Out Results variable to the Event Graph and select Get Out Results. Drag from the node, then search for and select Random Array Item.

    3. Drag from the Random node and connect it to the Request Results pin of the Claim node.

    Add a Claim node

    Drag from the node, then search for and select Random Array Item

    Drag from the Random node and connect it to the Request Results pin of the Claim node

  14. Right-click the Return Value pin of the Claim node and select Promote to Variable. Name the variable ClaimHandle.

    1. Drag from the Claim Handle node pin, then search for and select Is Valid Smart Object Claim Handle.

    2. Drag from the Return Value of the Is Valid Smart Object Claim Handle node, then search for and select Branch.

    Right-click the Return Value pin of the Claim node and select Promote to Variable. Name the variable ClaimHandle

    Drag from the Claim Handle node pin, then search for and select Is Valid Smart Object Claim Handle

    Drag from the Return Value of the Is Valid Smart Object Claim Handle node, then search for and select Branch

  15. Drag from the False pin of the Branch node, then search for and select Finish Execute.

    Drag from the False pin of the Branch node, then search for and select Finish Execute

  16. Drag the Blackboard variable to the Event Graph and select Get Blackboard.

    1. Drag from the Blackboard node, then search for and select Set Value as SOClaim Handle.

    2. Connect the True pin of the Branch node to the Set Value as SOClaim Handle node.

    3. Right-click the Key Name pin of the Set Value as SOClaim Handle node and select Promote to Variable.

    4. With the Key Name variable selected, go to the Details panel and enable the Instance Editable checkbox. Set the Default Value to ClaimHandle.

    Drag from the Blackboard node, then search for and select Set Value as SOClaim Handle

    Right-click the Key Name pin of the Set Value as SOClaim Handle node and select Promote to Variable

    Enable the Instance Editable checkbox. Set the Default Value to ClaimHandle

  17. Drag the ClaimHandle variable and connect it to the Value pin of the Set Value as SOClaim Handle node.

    Drag the ClaimHandle variable and connect it to the Value pin of the Set Value as SOClaim Handle node

  18. Drag from the Set Value as SOClaim Handle node, then search for and select Finish Execute. Enable the Success checkbox on the node.

    Add a Finish Execute node and enable the Success checkbox

  19. Compile and save the Blueprint.

Using the Smart Object

  1. In the Content Browser, double-click BTT_UseSmartObject to open it. In the Event Graph, right-click and search for then select Event Receive Execute AI.

    Add the Event Receive Execute AI node

  2. Drag from the Owner Controller pin of the Event Receive Execute AI node, then search for and select Get Blackboard.

    Drag from the Owner Controller pin of the Event Receive Execute AI node, then search for and select Get Blackboard

  1. Drag from the Return Value pin of the Get Blackboard node, then search for and select Get Value as SOClaim Handle.

    Drag from the Return Value pin of the Get Blackboard node, then search for and select Get Value as SOClaim Handle

  2. Right-click the Key Name pin of the Get Value as SOClaim Handle node and select Promote to Variable.

    1. With the Key Name variable selected, go to the Details panel and enable the Instance Editable checkbox. Set the Default Value to ClaimHandle.

    Enable the Instance Editable checkbox. Set the Default Value to ClaimHandle

  1. Drag from the Return Value pin of the Get Value as SOClaim Handle node, then search for and select Use Claimed Smart Object.

    1. Connect the Get Value as SOClaim Handle node to the Use Claimed Smart Object node.

    2. Drag from the Owner Controller pin of the Event Receive Execute AI node and connect it to the Controller pin of the Use Claimed Smart Object node.

    Drag from the Return Value pin of the Get Value as SOClaim Handle node, then search for and select Use Claimed Smart Object

    Drag from the Owner Controller pin of the Event Receive Execute AI node and connect it to the Controller pin of the Use Claimed Smart Object node

  2. Drag from the On Finished pin of the Use Claimed Smart Object node, then search for and select Finish Execute. Enable the Success checkbox on the node.

    Drag from the On Finished pin of the Use Claimed Smart Object node, then search for and select Finish Execute

  3. Compile and save the Blueprint.

Creating the Behavior Tree

  1. In the Content Browser, double-click BT_SO_Agent to open it. Drag from the Root node and select Selector.

    Drag from the Root node and select Selector

  2. Drag from the Selector node and select Sequence.

    1. Drag from the Selector node and select Wait. This node will have the Agent wait for 5 seconds before searching for a new Smart Object, if the initial search was unsuccessful.

    2. Make sure the Sequence node is to the left of the Wait node. This ensures the Sequence will be executed first in the Behavior Tree.

    Drag from the Selector node and select Sequence

  3. Drag from the Sequence node and select BTT_FindSmartObjects.

    Drag from the Sequence node and select BTT_FindSmartObjects

  4. Drag from the Sequence node and select BTT_UseSmartObjects.

    Drag from the Sequence node and select BTT_UseSmartObjects

  5. Drag from the Sequence node and select Wait. With the node selected, set the Wait Time to 2.0 and Random Deviation to 0.5. This node will have the Agent wait between 1.5 and 2.5 seconds before searching for a new Smart Object.

    Drag from the Sequence node and select Wait

    Final Behavior Tree

  6. Save and close the Behavior Tree.

Section Results

In this section, you created the Behavior Tree and Behavior Tree Tasks that allow the Agent to find and use Smart Objects in the Level.

6 - Creating the AI Agent

In this section, you will create the AI Agent that will search for Smart Objects in the level.

  1. In the Content Browser, double-click the ThirdPersonCharacter Blueprint to open it.

    Double-click the ThirdPersonCharacter Blueprint to open it

  2. Select all the nodes in the Event Graph and delete them. Right-click in the Event Graph, then search for and select Event Possessed.

    Right-click in the Event Graph and search for then select Event Possessed

  3. Drag from the New Controller pin of the Event Possessed node, then search for and select Cast to AI Controller. Connect the Event Possessed node to the Cast to AIController node.

    Drag from the New Controller pin of the Event Possessed node, then search for and select Cast to AI Controller

  4. Drag from the As AIController pin of the Cast to AIController node, then search for and select Run Behavior Tree. Click the BTAsset dropdown and select BT_SO_Agent.

    Drag from the As AIController pin of the Cast to AIController node, then search for and select Run Behavior Tree

  5. Compile and save the Blueprint.

  6. In the Content Browser, double-click the ThirdPerson_AnimBP Blueprint to open it. In the AnimGraph, right-click then search for and select Default Slot.

    In the AnimGraph, right-click then search for and select Default Slot

  7. Connect the Default state machine to the Source pin of the Slot ‘Default Slot' node. Connect the output of the Slot ‘Default Slot' node to the Results pin of the Output Pose node.

    Connect the Default state machine to the Source pin of the Slot ‘Default Slot' node. Connect the output of the Slot ‘Default Slot' node to the Results pin of the Output Pose node.

Section Results

In this section, you created the AI Agent Blueprint that will search for Smart Objects in the Level. You also modified the animation Blueprint to make sure the animation montage can play correctly.

7 - Testing the Smart Objects

You will now test the Agent to make sure it can find and use the Smart Objects in the Level.

  1. From the Main Toolbar, click Add Content (+) > Volumes > NavMeshBoundsVolume to add a new Navigation Mesh actor to your Level. Scale the Mesh to cover your Level so the Agent can navigate to its destination.

    Add a NavMeshBoundsVolume to your Level

  2. Drag several BP_SO_RunBT Blueprints to your level.

    Drag several BP_SO_RunBT** **Blueprints to your level

  3. Drag the ThirdPersonCharacter Blueprint to your Level.

    Drag the ThirdPersonCharacter** **Blueprint to your Level

  4. Press Simulate to see the Agent find and use Smart Objects in the Level.

    Press Simulate to see the Agent find and use Smart Objects in the Level

Section Results

In this section, you confirmed that the Agent can find and use Smart Objects in the Level.