Smart Objects and You in UE5 — Pt.1 What is Smart Object?

Ostap Leonov
5 min readMar 6, 2024

--

Every game needs an interaction system.
Regardless if that is RPG, FPS, Racing Game etc.
And making a good one is a hard thing to do, especially if you want ease of use, networking support and a good underlying architecture.

But with the release of Unreal Engine 5.0, Epic Games introduced their take on interaction system and solved most of the problems we all being bragging about, or did they?

This is the first article of a mini-series “Smart Objects and You” in which we will cover the process of creating an interaction system from ground up based on Smart Objects both for AI and Players, talk about Networking and Replication caveats as well as some tips-n-tricks i learned along the way.

In this part, I will give an overview of what “Smart Objects” are and how they work from the inside

The source code for this series will be available on GitHub.
Comments, suggestions and/or any form of discussion are always welcome.

So what are Smart Objects?

Smart Objects provide interaction functionality for the actors that contain SmartObjectComponent, which points to smart object runtime object.

Smart objects are divided into slots that contain context for each interaction.

Slots on a Smart Object Actor

Each slot has its own state, as well as the action that player has to execute when he uses the slot.
Those could be either playing an animation, executing Behavior Tree or some custom defined logic.

And the states represent the availability of Smart Object — as you can see on the picture below.

AI only requests to receive presents when it is fully “seated” at the table, and stops the requests for the Table when leaves

Red(Used) — Smart Object is occupied
Yellow(Claimed)- player reserved this slot, but didn’t arrive at the position of the slot yet.
Green(Free) — the slot is free and can be queried and used.

To define Smart Object you’d need to create a Smart Object definition — an asset which basically defines rules that will apply to Smart Object when using it, as well as the slots, their position, actions they will trigger, selection conditions etc.

Smart Object Definition Editor

Slots also can also have additional data defined as custom FSmartObjectSlotDefinitionData and put into Data array.

Under the hood

Under the hood, Smart Objects use spatial database to partition and search using actors bounds to determine the closest Smart Object and slot to the querier.

There are two aviliable USmartObjectSpacePartition classes - USmartObjectOctree or USmartObjectHashGrid
They currently default to Spatial Hash Grid implementation, although, this can be changed in config.

Bounds used in SmartObjectSpacePartition(highlited in blue)

After the spatial search, Smart Objects are filtered using

  1. Selection Preconditions — user defined functors, which are used to filter out SO on specific condition. They inherit FWorldConditionBase class, and use World Conditions plugin to handle all condition logic.
  2. User tags — tags user must inherit to use this specific SO
  3. Activity tags — optional tags that distinguish SO, only used during the search
SmartObject use scenario flow

There’s are also two other frameworks that come to play, when it comes to smart objects —

  1. MASS, which is used for data storage
  2. Gameplay Behaviours, which is used for scripted actions

MASS

MASS — is an ECS framework inside of Unreal Engine. Specifically Mass Gameplay plugin, as the MASS framework is split into different plugins for crowd control etc.

So Mass Gameplay, being an ECS system, introduces things called “Mass Fragments”, which could be explained in two words — “data containers”
Though this explanation may not be really correct, but you get the point

And as you may already guessed, Smart Objects use Mass Fragments as their data storage.
Every data, that is tied to Smart Objects at runtime, is represented as a FMassFragment.

The main reason for this is it’s efficiency. Storing large amount of runtime data is mandatory, as smart objects contain a lot of metadata junk that is persistent at runtime.

If you’d like to read more about MASS, I have a links to some amazing documentation from Unreal community below.

Gameplay Behaviors

Though being a separate plugin, those are basically “AI Tasks for Smart Objects”.
Anyone who had experience using BTTasks or Gameplay Abilities, could see some simularities between the two.

Gameplay Behaviors represent incapsulated logic, which will be executed when smart object is being used by Character.

Player or AI

If you seen the City Sample project, you probably won’t be surprised to learn that Smart Object implementation there is only meant for AI.

As a matter of fact, all of Smart Object system is mostly build around AI use only.
Still there is no blockers which prevent you from using this on Player characters.

The only thing to keep in mind, that replication support for SmartObjects, is really limited. The main bottlenack being the FMassFragments that store smart object data.
As of UE 5.2 those are not replicated.

Still, there are ways to replicate some data you may need from Smart Object system.
We will cover the replication and Player usage in the next part of the series.

And as for today, this is it.
In the next part we are going to cover Gameplay Behaviours and Smart Object data storing.

Useful links

Github — https://github.com/LeonovOstap/SmartObjectsUE

Mass Community Sample by namo, check it out for some info on Mass aswell as ECS in general— https://github.com/getnamo/MassCommunitySample

--

--

Ostap Leonov
Ostap Leonov

Written by Ostap Leonov

Lead Unreal Developer. Like to write stuff

Responses (2)