Using the Smart Object system

The Smart Object System allows us to create objects that, when used by an interacting character, will perform specific actions. These actions can be, for example, playing an animation on the interacting character, changing the character's position, affecting AI parameters, and more. The logic of how to interact with an object can thus be stored on the object itself instead of the character.

The system is inspired by a built-in feature of Unreal Engine 5, but it's not the same, and it's customized for our codebase.

This article serves as a tutorial on how to use the system.

Smart Object Elements

Smart Object Slot Component

To make a regular object into a smart object, we attach a component called SmartObjectSlotComponent to the object. A Smart Object slot component is a scene component - it has a location.

However, this component alone will not add any functionality, and it is the objects called Smart Object functions that are used to add functionality. These functions are executed when the Smart Object slot is used.

Smart Object Function

Smart Object functions perform specific tasks such as launching an animation, moving a character to a specific location, and so on.

Multiple functions can be used on a single Smart Object, which can then be used to compose the desired effect - for example, if we wanted to create a place where an NPC would dance, we would use the Smart Object function to move it to a specific location, along with a function to play an animation.

Smart Object Condition

Sometimes we want to restrict the use of a Smart Object only when specific conditions are met. For this we use Smart Object Conditions - objects that are attached to the smart object just like smart object functions. Functions are executed only if all attached conditions are met. An example of such a condition can be restricting the use of an object to its owner only or restricting the use based on the interacting character type.

How to create a Smart Object

How to create a simple Smart Object:

Before making a whole new smart object, try to see if any of the presets in Game/Systems/SmartObject/Slots , like SOS_SimpleAnim . The functions and conditions are configurable.

You can also create your own preset if you’re going to re-use it several places

A list of all core functions and conditions is available at Game/Systems/SmartObject/SOS_AllCoreFunctions

  1. Add a new Smart Object Slot Component to the actor.

  2. Add a new elements to the field named Smart Object Functions and select the appropriate function from the list of Smart Object Functions (for example, SOF_Anim ). You can add multiple functions. You can do the same with the field Smart Object Conditions

  3. Those objects can then be configured - expand the smart object function element and modify the function parameters (for example, for SOF_Anim , select the animation you want to play)

How to use a Smart Object Slot

This section is only useful when you are trying to make a new kind of object that uses smart object slots. Placeables already have all of this set up by default (see the section below).

Use the functions presented here for prototyping, but please start a discussion in the smart object slack channel before submitting stuff for good, to see if it’s the best approach

General set up

To use the Smart Object manually, just call the Use function on the component. In the case of interactable objects, for example, we can override the Event Interactable Activate , in which we call the Use function.

When we are done using the Smart Object, we need to release the character that uses the Smart Object slot. This is done by calling the ReleaseCharacter or DeactivateSlot function on the smart object.

Placeables (example)

Players : if there is no override of the interaction logic in a given placeable, the base interaction logic of BP_Master_Placeables will trigger to handle smart object slots. When a player interacts with such a placeable, it will trigger interaction with the closest smart object slot that is available for the player.

Moving or pressing interact again should stop the interaction with the smart object slot.

Thralls : The thrall system component will be the one handling the smart object system. When moving or placing a thrall, it will display all of the available smart object slots in proximity using ghost humanoids. When the placement brush gets close, placing the thrall will immediately trigger using the slot.

How to get NPCs to detect nearby slots

Smart Objects can be searched using the Smart Object Manager . Here we find the function GetAvailableSmartObjectSlots(Location, Radius, InteractingActor, GameplayTagQuery) .
The parameters are:

How to set up a character to use a prop

Setting up a character to perform an animation with a prop is done in two steps:

  1. Creating a Smart Object with SOF_Anim that utilizes its Props property to identify skeletal mesh components that should be used as props.

  2. Setting up a UseProp anim notify state on the animation montage that will attach the prop to the socket on the interacting character.

This should also work with SOF_Emote and SOF_AnimBlueprint

Here is an example of placing a skeletal mesh on a placeable table that the interacting character will be able to pick up:

  1. Add a new Skeletal Mesh component to the placeable (in this example case, it’s BP_PL_Table_1 ). Set its Skeletal Mesh and Anim Class properties.

  2. Add a new Smart Object component with the SOF_Anim function. Set the Animation to the desired one to perform when interacting with the smart object. Also, add the name of the skeletal mesh prop to the Props array. The skeletal mesh component will be found by name among skeletal meshes of the smart object and sent to the animation system.

  3. Now, we have to set up the UseProp anim notify state to allow the character to pick up the prop and attach it to their socket. To do this, edit the animation montage we set in SOF_Anim . In our example case, we will be modifying AM_emote_greet_wave_casual . The parameters of the anim notify are as follows:

    1. Prop Index : the index of the prop in the Props array on SOF_Anim .

    2. Attachment Socket : the socket to which the prop should be attached. Select none to bypass the attachment

    3. Attachment Rule : the rule for attaching the prop

    4. Prop Animation an optional animation or animation montage to play on the prop when the notify begins.

    5. Prop Animation Play Rate with this, we can adjust the play rate of the optional prop animation.

    6. Prop Animation Blend Out Time the blend-out time for the optional prop animation in case the notify ends before the prop animation montage finishes.

  4. Now we can either place a thrall at the location of the Smart Object slot or use the slot via the interaction mechanic, as described in 'How to use a smart object slot.' The interacting character starts playing an animation with the prop in their hand.

Tip: We can add the SOF_ForceTransform to force the interacting character to stand in the desired location and look at the prop.

When to use SOF_Emote

By default, SOF_Anim should be used as it’s the most straightforward to set up. However, in some cases, we do need to use an emote:

Here are some articles related to the topic of Smart Objects:

Smart Objects documentation

Smart Objects inside Unreal Engine 5