UE5.4 State Tree Data Management
Summary
TLDRThe video transcript discusses various methods for managing data within Unreal Engine's State Trees. The speaker starts by mentioning changes in the latest version (5.4) and then delves into the topic of data management, which is not frequently covered. They explore the concept of using a separate U object or a derived object to store data, suggesting the creation of a blueprint class called 'BP Store' for this purpose. The speaker also touches upon the use of Blackboards, traditionally associated with Behavior Trees, and how they can be utilized with State Trees. A new feature in Unreal Engine 5.4 is highlighted โ the State Tree AI Component, which allows for easier access to the AI controller class and can be used for data management. The video concludes with an innovative idea of storing data directly in the State Tree component, akin to using a Blackboard, and demonstrates a practical example of tracking and displaying an AI character's movement history within the game environment. This approach is presented as a versatile solution for both AI and non-AI actors.
Takeaways
- ๐ The video discusses data management within Unreal Engine 5.4's State Trees, a topic not extensively covered online but mentioned in the comments of a previous video.
- ๐ The presenter suggests using a separate U object or a derived object to store data, which can then be utilized within the State Tree for managing variables.
- ๐ฆ An alternative method involves using a Blackboard, a concept traditionally associated with Behavior Trees in Unreal Engine, which can also be experimented with in State Trees.
- ๐ Unreal Engine 5.4 introduces a new schema for State Trees, the 'State Tree AI Component', which provides direct access to the AI controller class.
- ๐ก The presenter proposes a novel idea of storing data directly within the State Tree component, effectively using it as a Blackboard, which simplifies data management.
- ๐ A custom C++ class is created to extend the functionality of the State Tree component, making it accessible and mutable within Blueprints for easier data management.
- ๐ ๏ธ The presenter demonstrates how to compile and use the custom State Tree component in C++, emphasizing the need to include specific modules for successful compilation.
- ๐ The new component allows for the storage of data in a map structure, similar to a Blackboard, which can be manipulated using Blueprints for a more visual and intuitive experience.
- ๐ An example is provided where the component is used to store and visualize the history of an AI character's visited locations, showcasing the practical application of the data management method.
- ๐ The video concludes with an invitation for viewers to share their own ideas on managing data in State Trees, encouraging community engagement and further exploration of the topic.
- โก๏ธ The presenter highlights the flexibility of the method, which works with both AI and non-AI actors, and emphasizes the ease of use by integrating directly with the State Tree component.
Q & A
What is the main topic of discussion in the video?
-The main topic of discussion in the video is data management within Unreal Engine's State Trees.
What is the first method suggested for managing data in State Trees?
-The first method suggested involves using a separate U object or deriving from a U object to store data, such as creating a blueprint class named 'BP Store' to hold variables.
What is the role of a global task in the first method of data management?
-In the first method, a global task is used to create or construct an object from the 'BP Store' class when the state tree initializes.
What is a straightforward way to store data in Unreal Engine?
-A straightforward way to store data is to add variables directly to the class of the character that the state tree is being used on and then access these variables through the context actor.
What is a Blackboard in Unreal Engine?
-A Blackboard in Unreal Engine is an asset used traditionally with Behavior Trees to store data. It contains keys that can be set or retrieved to manage data across different parts of the AI system.
How can Blackboards be used with State Trees?
-Blackboards can be used with State Trees by using an AI controller to link the State Tree to the Blackboard. However, this method is more commonly associated with Behavior Trees and may require additional steps to integrate with State Trees.
What is new in Unreal Engine 5.4 regarding State Trees?
-Unreal Engine 5.4 introduces a new schema called 'State Tree AI Component' which allows for the creation of different kinds of state tree assets with direct access to the AI controller class.
What is the proposed alternative method for data management without using a Blackboard, actor class, or constructing a new object?
-The proposed alternative method is to store data directly in the State Tree component, using it as a Blackboard to manage and store variables.
How does creating a custom C++ class for the State Tree component help with data management?
-Creating a custom C++ class for the State Tree component allows for the exposure of specific variables and functions to Blueprints, enabling the storage of data within the component in a structured manner similar to a Blackboard.
What is the benefit of storing data in the State Tree component?
-Storing data in the State Tree component allows for a centralized location for data management that is automatically initialized with the component, making it convenient and reducing the need for manual setup or initialization.
How does the video demonstrate the practical use of the new data management method?
-The video demonstrates the practical use by showing how to store and replay the history of visited locations of an AI character using the map vector within the State Tree component.
Outlines
๐ Introduction to Unreal Engine 5.4 and Data Management
The speaker begins by welcoming the audience to Unreal Engine 5.4 and mentions that they previously worked with a preview version. They note that while many things have changed, they will only discuss one significant change related to the topic of the day, which is data management. The speaker briefly mentions a comment from a viewer about managing data in state trees and suggests using a separate U object or a blueprint class to store variables. They also touch upon the concept of creating a global task within a state tree to manage data.
๐ Exploring Data Storage Options in Unreal Engine
The speaker discusses different methods for storing data within Unreal Engine, such as using an actor class or a new object within the state tree. They also mention the use of blackboards, a feature traditionally associated with behavior trees, and how they can be used with state trees. The speaker highlights a new schema introduced in Unreal Engine 5.4, the state tree AI component, which provides direct access to an AI controller class and allows for more complex data management.
๐ก Innovative Data Management Using State Tree Components
The speaker shares their idea of managing data by storing it directly in the state tree component, similar to using a blackboard. They explain the process of creating a custom state tree component in C++ and exposing it to blueprints to allow for data storage. The speaker demonstrates how to add variables to the component and how these can be used to store and manage data within the state tree.
๐ ๏ธ Creating a Custom State Tree Component in C++
The speaker provides a step-by-step guide on how to create a custom state tree component in C++ and make it accessible in blueprints. They discuss the importance of adding necessary modules for the project to compile successfully. The speaker also shows how to implement functions to get and set the state tree asset from within the custom component.
๐ Storing and Retrieving Data with the Custom Component
The speaker illustrates how to use the custom state tree component to store and retrieve data. They demonstrate adding a map vector to the component, which can be used to store vectors as keys and values. The speaker also shows how to access the component from a blueprint class and how to store and manage data using this method.
๐ Implementing a Data History Feature with the Custom Component
The speaker presents an example of using the custom state tree component to implement a data history feature. They explain how to store visited locations in a map vector and then use this data to draw debug lines, showing the history of the character's movements. This example demonstrates the utility of the custom component for managing data in both AI and non-AI actors.
Mindmap
Keywords
๐กUnreal Engine 5.4
๐กData Management
๐กState Trees
๐กBlueprint Class
๐กBlackboard
๐กAI Controller
๐กC++
๐กComponent
๐กMaps
๐กDebugging
๐กBehavior Trees
Highlights
Introduction to Unreal Engine 5.4 and its changes from the preview version.
Discussion on data management in state trees, a topic not widely covered but requested by viewers.
Suggestion to use a separate U object or a derived object to store data for state management.
Explanation of creating a blueprint class called 'BP Store' to hold variables like test Boolean and test float.
Demonstration of using a global task to construct an object from the 'BP Store' class within a state tree.
Alternative methods for data storage in state trees as opposed to using the character class directly.
Introduction of using Blackboards, traditionally used with Behavior Trees, with State Trees.
Description of Blackboards as assets with keys for storing data and their potential use with State Trees.
Mention of a new schema in State Trees 5.4 for AI, providing direct access to an AI controller class.
Proposal to store data directly in the State Tree component as an alternative to using a Blackboard or actor class.
Walkthrough of creating a custom State Tree component in C++ for exposing to blueprints.
Explanation of adding a map vector to the custom State Tree component for data storage.
Demonstration of storing visited locations in the map vector and drawing debug lines to show the history.
Discussion on the flexibility and potential applications of this data management method for both AI and non-AI actors.
Advantages of this approach, including the ease of use and automatic initialization with the State Tree component.
Encouragement for viewers to share their ideas on managing data in state trees.
Invitation for viewers to like, comment, and subscribe for more in-depth videos on Unreal Engine.
Transcripts
hi am here and welcome to Unreal Engine
5.4 in the release version last few
videos we worked with preview version
some things changed I'm not going to
talk about all of them uh but I am going
to talk about one but it's not the topic
of this video it's just you know a side
subject I'm going to just mention
quickly because it's kind of related to
what I'm going to be talking about today
but it's not the uh the main part
okay so what is the today's topic well
it's data management and uh
well this is a topic I have seen uh kind
of mentioned not a lot but a little bit
uh on internet and uh actually somebody
mentioned uh mentioned this in the
comments of my 5.3 updates video and
this guy
mentioned well data management in state
trees and you can you know kind of read
or just go to that video watch it and
then read the comments and and see what
you think about them uh about those
those comments but uh in just the
conversation were about uh how do you
manage data in in States right and one
kind of uh one kind of way I suggested
that we could go about this uh was using
a separate um a separate U object or
just object or maybe a different kind of
object you derive from you object and
just store data there so the principle
would be like you make a blueprint class
you make uh just an object uh you call
that object BP store or or what ever and
in that object you just you know store
some variables like uh test Boolean test
test
flat and so and so on and in the actual
state tree you would just you know uh
probably make a global task and in that
task you could you could probably make a
new state three
task right and in that task you say s
init and in that init on enter State you
will just you know create
object or construct rather
construct I can't write today construct
object from class
pick. store
class right I I can't even hit
it as store BP store right and just you
know promote
variable put that to H to an
output I I need to
focus
output category uh and
then you
would put it here and now we have Star
as output and then if we wanted to uh
you know make another state state would
be like move and mve to yes move to and
in that task we would add let's say move
to and we could just pass that uh store
to that task and maybe store some
variables in that uh object right so
it's like one of ways you could go about
storing uh
data uh and of course this is all an
alternative to what you would normally
do normally do if you would want to
store some data because the very
straightforward and the most
straightforward straightforward way
would be to um go to Just class of the
character you are using the state Tri on
and just you know store variables there
and then when you use that task you just
you
know uh context actor
right take that
context
actor and uh put a class there and just
you know take it
out and just you know set set variables
right but uh the reason we are talking
about Alternatives is that maybe we
don't necessarily want to St uh store
variables straight in that in that actor
right so we are kind of you know
chilling today and desing a few
different ways we could go about doing
this and uh yeah we're just going to
chill and see what else we can do so my
option well before we go to the next
part I of course encourage you to watch
my video about stries last state trees
video where I actually made those State
trees uh I showed linked assets I showed
um some other updates colors and stuff
of new stuff that came from uh Unreal
Engine 5.4 in preview version and you
would know why do I have those assets
and why they are struct structured like
that and uh okay moving
on how do you store data well either an
actor class or what I just show you so a
new object that you can just in it in uh
the state tree or you could do what this
guy did and this guy did uh
basically he went back to uh to the
Blackboard and blackboards if you are
not aware blackwards are used or were
used or
both uh with behavior trees so Behavior
trees are uh I would say but you can
like not agree with me it's a like
version of uh you know doing AI in
Unreal Engine because uh I consider
State trees to be superior and you know
an xgen version of behavior trees and
behavior
trees traditionally used and still used
if you want to use Behavior trees today
uh blackboards and blockboards are types
of assets that are kind of tied to uh
Behavior trees but not necessarily I
mean you can not tie them but you would
usually do that and you would store data
there so blackboards do look like uh
this so you just go to Blackboard and in
Blackboard you have this you have keys
and you can add more keys with I Vector
key or maybe a a name key right you name
all of that
however you want and then in Blueprint
you would just go uh yeah set
Blackboard or maybe not like we probably
need to get Blackboard first excuse mua
for not being a pro at blackboards and
behavior trees I kind of like didn't do
much of AI before State trees so I
didn't look at Behavior twist that much
uh but you would get a Blackboard and
then you can get value as class Bull
inam Float in whatever
or set value as float and da D and
whenever you select that uh that node so
set value as class or bull or whatever
then you pass a key and that key
corresponds to whatever is here so if we
want to change that Vector key then we
would pass you know a Lal name or
whatever variable you want uh and then
just type Vector key right and that
Vector key well this doesn't make sense
of course because you would want to set
value as uh as Vector right and then
just you know pass whatever Vector you
want and uh all of that is stored in the
in the Blackboard so how do we use
blackboards with State trees I mean you
kind of don't really but you still can
and if you
know uh I mean if you want to experiment
and try anyway then go for it read that
comment uh I think it's a great idea if
you want to um work with
blackboards and this guy used actually
AI controller to hook State Tre to it to
it and then kind of do a few more steps
to uh to achieve that purpose
and one thing new from State Tre 5.4 in
the release version was actually a new
schema so when we go to artificial
intelligence state
tree now in addition to state three
component and probably game interaction
yeah this is also a schema we have state
three AI component and if we pick that
AI component now we can make a different
kind of state tree assets and those
assets uh I already made one here it's
this state AI component schema when we
open this we have a controller class so
this state tree asset is basically
guaranteeing uh an access to AI
controller class so probably what this
guy did would be easier now with the 5.4
release version because you know you
have direct access to a controller and
you can do more stuff uh so yeah that's
the that's the third way you can uh
store or manage data in in state
trees and I guess one thing I wanted to
show you is oh yeah this uh so
description for State Tre II components
is just it guarantees access to an i
controller and the actual context value
can be used to access the control P
right so just you know expanded version
of State Tre
asset uh the uh normal asset we had at
until this point right it's just you
know we added one more variable
um and this give me G gave me an idea
like how else could we manage data and
you know store some variables if we
don't want to use a Blackboard and if we
don't want to store variables straight
in the actor and we don't really want to
play with constructing a new object so I
was thinking like hey okay we have a
component uh State 3i component we have
this you know uh a class AI controller
class we can have context actor
class and all of that is basically
stored in a component we have to add
anyway to you know um use stage tree
with an actor and uh this guy so a
Bernardo uh it works only with AI right
so if we hook a Blackboard and we try to
use the Blackboard with II controller
then we kind of on we are only stuck
with uh AI right and if we wanted to
store or manage data in actors other
than AI then you would need a different
approach right and it's like no longer
VI viable and you still could store data
in the actor class and and do this
approach but I think I have something
better so uh my idea is to store data
straight in that
component right so just use it as a
Blackboard and and the uh stage Tree in
one component I mean it's uh probably uh
controversial like you could disagree
with me and say h we need to decouple
the logic and the data read and you
would be right in some way right but I
don't necessarily like it and I think
this uh way has its upsides so how do we
store data in that component first of
all when we make a state tree component
right with with type state three like
this and we also have state three II
because I didn't tell you that but to
use that new schema you have to use new
component or it just doesn't show right
we have I base follow R but we don't
have um s AI base which is State Tre II
component schema and we don't have of
course this because it's gameplay
interactions from uh my previous video
so yeah you have to add a new type of
component to use it and when you do add
well any of that is basically this right
you actually cannot get that asset you
cannot set it and you cannot do anything
meaningful to that because all of that
is stuck with C++ and if you know me
then you know uh I'm not a huge fan of
C++ so I prefer to to do everything in
uh in blueprints but sometimes C++ is
inevitable so I went today to C++ and I
made a new class because uh to actually
expose what I want to expose to
blueprints we have to do this in C++ so
what did I do I made my own state three
component and that state three component
is actually exposed to a blueprint so
yeah my idea is that we have a state Tre
component and then we have variables
that actually just store data and they
are structured in a way that it's kind
of similar to Blackboard so we have Maps
uh we have like vector map we can do
float map or we can do
even uh make a separate object which is
BP star and then just construct it when
the uh state component is activated
which is I mean if you want to do this
uh this is just uh you know rumbling
thinking loud kind of thing
experimenting so there is a lot of way
you can improve that system but yeah
let's just do this right straight in the
in the straight state tree component and
see how this works so I added just a map
Vector because I don't really want to
add all of those things that are in the
Black because yeah we just want to test
it right see if that works um and how
did I make that state Tre component
because if you go to blueprint class and
you type State
Tre then uh this won't show all of that
won't show and even if it does then you
can't make a blueprint out of this but I
made my own uh child class of State Rec
compos component in C++ and then I made
it blueprint so I made a state Tre
component that is actually a blueprint
and it's actually a super
straightforward to uh to do you don't
have to be a master at coding I'm just
I'm just going to you know jump straight
into the visual studio show you how to
do this and how to actually expose some
new functions that will or will not but
probably will be useful to you in later
date probably uh so let's jump into
visual studio and this is how my project
looks so we have that MRK state three
component which you can see here or
rather here because the that blueprint
state three component is uh a child of
am State Tre component and that is a
custom C++ class I made here and that is
of course uh in it from normal State Tre
component and to actually compile it and
use it don't forget to add very
important modules uh which are
um
[Music]
written here uh build find your build Cs
and add those to modules otherwise yeah
your project just won't compile and you
will be stuck so uh I was actually stuck
with this for a while because I the
error messages are not very helpful
sometimes but yeah you just need to add
those modules and you are good to go and
then what you want to do I just did it
in that age but you can of course
implement this in uh that CPP whatever
you want and those two functions I added
here uh is get State Tre asset and set
state assets so now from blueprints we
can just you know uh take that component
we can now get it and get state three
asset and now we can do something with
it maybe we can uh kind of save it and
we can of course set state tree
asset and yeah just pick whatever you
want so yeah very very very nice very
cool and when you do that make sure to
uh mark this class as blueprint
and all of that I just copied from uh
use stage three component so just you
know copy this and paste and just add
blueprint B so you can make a blueprint
class out of that
component and then those functions well
I just made this pure and this is cable
and you might wonder why this is get
mutable State Tre uh it could probably
work with just get state three but get
state three returns a constant state Tre
so You' have to add const here and
maybe uh maybe it will have some
problems later I don't know but mutable
is just a straight pointer so I decided
to H to go with this and this is all of
the code right you just make a new C++
function do do this right can zoom if
you
want rewrite it whatever and compile and
you're good to go right and then you
make a new blueprint class you write
State
Tre PB state three component select and
you make your own component and now you
can have variables in that component and
whenever you want to store something you
just go to uh whatever you can do this
in STD as well so let's go to in it
whatever and from Context class we can
just get uh MRK or um how is it called
BP State Tre
component and
uh State Tre component it was down here
I don't know why didn't show before but
okay we have that BP state three
component and then we just take my M
vector and we can store whatever vectors
we want as keys and values in that map
variable straightforward and simple to
use and I think will be quite power
powerful if you find a nice use for it
so H what would be my use for it okay I
hear you ask and very good question I'm
going to I'm going to answer it right
away because I have prepared an example
for you guys and that example
involves n nothing other than that map
Vector so if you remember in our let's
just maybe close all of that in our
St base St AI base we have two states
right we can roam we can follow all of
that is dependent on the
um on the bull variable that we have in
or we should have in in BPI but now we
don't for some reason I don't know why
uh let's quickly maybe check yeah that
actor follow kind of
disappeared let's make it again follow
and Mark it false we compile and yeah we
are good kind of let's just reattach
this where is the follow here
okay follow follow and here it is good
so in that uh AI base we just go to
follow if the actor is going to be
followed R if not and in AI Rome we have
that St move to so um in my original
example it was just 05 and it would also
use as smart objects but for purpose of
this video I just made it once so it is
always picking that state and that state
is using St move to which we will use
for our example so what is the current
purpose of the of that uh St move to
well the purpose uh we want to um show
today or experiment with is well we find
a random position in the reachable
radius or rather reachable point in
radius and then we go to that point so
that's the OG example and now with this
um kind of you know data management we
can save those locations sorry I'm kind
of like um dry throat excuse
M
okay we can store those values and maybe
[Music]
be show a history of visited locations
like this is probably something that
could be useful in a real world scenario
right so let's do this and in our St
move
to this is the the same code we uh we
saw in the uh UE 5.4 preview updates
video so you can just you know watch
that but it's really not not complicated
get H get the location select if random
destination true then yeah get that and
I am move to and then what we can do is
just get that state three component take
the map vector and add a value to that
for key I'm just using time so this is
BPU deals and it's using QTC now to make
a basically unique key because I don't
really need to name those uh values so
it could just be an Ray instead but yeah
we we are going with um with a map so I
just made you know uh a key that is
always unique so we add that position to
a vector and then when we you know on
success it's all on success then we got
all of the keys and we look through
through them and we make a draw debug
line which takes one position and the
next
position and this is basically how you
make a data history so now
whenever the uh the character moves it
stores a position in that map
and when he gets to his location it just
replay all of his visit locations and
draws nice debu lines so yeah that's
that's the example for these uh data
management method and there are probably
many more that you could do but this one
I think is pretty pretty cool and will
work with AI and non AI actors and you
can just you
know forget about initializing anything
you can just you know add this and when
whenever you want to store something
then you just take that BP component
store it in the map forget about it and
it's all initialize it with uh the stage
component so you don't have to remember
about remember anything right just add
stage you would normally add and it
already comes with uh maps that you can
use to start values so that's uh my
little idea I hope you enjoy it and tell
tell me what are
your ideas on how to manage data in
state
trees so that's it uh drop a like drop a
comment drop a sub of course most of you
like 95% are not subbed and you should
be subbed because I made uh Bunger
videos like this one and see you next
time bye-bye
5.0 / 5 (0 votes)