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.
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 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.
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 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
Add a new
Smart Object Slot Component
to the actor.
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
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)
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
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.
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.
Smart Objects can be searched using the
Smart Object Manager
. Here we find the function
GetAvailableSmartObjectSlots(Location, Radius, InteractingActor, GameplayTagQuery)
.
The parameters are:
Location: the place around which we search
Radius: search radius
InteractingActor: the character that will interact with the SmartObject
GameplayTagQuery: additional query to match against slot type
Setting up a character to perform an animation with a prop is done in two steps:
Creating a Smart Object with
SOF_Anim
that utilizes its
Props
property to identify skeletal mesh components that should be used as props.
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:
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.
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.
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:
Prop Index
: the index of the prop in the Props array on
SOF_Anim
.
Attachment Socket
: the socket to which the prop should be attached. Select none to bypass the attachment
Attachment Rule
: the rule for attaching the prop
Prop Animation
an optional
animation or animation montage
to play on the prop when the notify begins.
Prop Animation Play Rate
with this, we can adjust the play rate of the optional prop animation.
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.
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.
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:
If we want to support an intro/looping/outro animation structure (see
BP_PL_NemedianLibrary_Stand
)
If we want to check for entitlements (the character owning the emote to be able to play it at the smart object slot). In that case, we should use
SOC_HasMatchingItem
with
HasEmoteItemForMatchingSOF
to check whether the current emote item is owned.
Here are some articles related to the topic of Smart Objects: