I am working un UE5.1 and am unable to assign a State Tree Object to a State Tree Component. I’d like to use a data asset that contains my ST and only create the component if the data asset is in use.
Currently I am adding a bunch of ST components to my Bp and leaving them blank and not set to auto start. Then I make an array of said components and resize based on a number provided in the editor. Which works, until you forget to load in a state tree to a component.
I’m looking at the same issue. As far as I can tell although it is possible to create a variable of type StateTree there does not seem to be a way to assign it to a state tree component. I think that State tree setting must therefore be compile time not run time.
1 Like
Hello ,
in case you’re still looking for an answer :
FStateTreeReference StateTreeRef;
this is the variable inside the UStateTreeComponent that holds a UStateTree object inside,
create a c++ class and chose UStateTreeComponent as parent
.h
UFUNCTION(BlueprintCallable) void SetTree(class UStateTree* TargetTree);
.cpp
void UXStatetreeComponent::SetTree(UStateTree* TargetTree)
{
StateTreeRef.SetStateTree(TargetTree);
}
don’t forget to update yourproject.build.cs and add these:
“AIModule”,
“StateTreeModule”,
“GameplayStateTreeModule”,
to the public dependencies
UCLASS(BlueprintType, meta = (BlueprintSpawnableComponent))
and also have this at start of the header so you can actually add the component in editor
3 Likes
Well I have the same issue but since as you noted we can store the state tree in a variable maybe they just forgot to add the blueprint function to set it at runtime ? Does anybody know if it will be one of the next releases? Looks quite strange to me
For anyone looking for a more comprehensive example of how to accomplish runtime StateTree swapping, you can have a look at this GitHub repo.
I’m really looking forward to seeing Epic expand StateTree functionality. It’s a top-tier addition to the engine, and it deserves some love!
1 Like