Behavior Graph Enum Switch Case

Thanks for the reply on my latest question, very cool.

Right now I’m trying to make a Sims Clone. In SelfMoodChecker I have an enum that returns which mood the gameobject is in. Then I want the behavior graph to choose behavior with the switch case based on the mood. But it seems that I can only assign the Enum blackboard variable with a single mood from the inspector? Because I don’t want the enum value to be constant, I want it to be changed depening on mood. Is there a way for me to change the enum value somehow? Or am I going about it all wrong?

Hello @fiskmaslok

I’m not sure to understand the specific issue you are trying to get help from.

Are you asking for way to set the enum value at runtime? If so, it is possible to set blackboard variable in a behavior graph using the Set Variable Value node.

It is also possible to do so from code using the BehaviorGraphAgent.SetVariableValue API.

Thanks for the quick answer, Morgan. I tried implementing your suggestions but I’m not sure if it works for what I’m trying to do, or maybe I did it wrong.

I have this script,


which returns a mood.
Then I have this script, where I try to set the blackboard variable to the mood returned from CheckMood.

But it seems that I can only set the variable here:

or here in the inspector:
image
What I choose in the inspector or in the blackboard seems to overwrite anything I tried to set through code. Is there anything else I can put on this line:
image
to make the switch actually branch off to the correct mood?

If I understand well, you need to assign your New LowMood blackboard variable to the LowMood field by clicking on the link icon next to the enum value:

You can also drag and drop your blackboard variable to the field.

:woman_facepalming: that seems so obvious now, I just got confused because I could already assign a value even though I hadn’t dragged in the blackboard variable I guess.
But big thanks Morgan! You’re the goat!!

1 Like