Reply To: FSMOwner.SwitchBehaviour() functionality not working synchronously?

NodeCanvas Forums Support FSMOwner.SwitchBehaviour() functionality not working synchronously? Reply To: FSMOwner.SwitchBehaviour() functionality not working synchronously?

#17796
Gavalakis
Keymaster

Hello,

Everytime a new FSM is loaded (eg SwitchBehaviour), an instance of the original FSM is created and loaded to the FSMOwner to use. This is why setting variables manually after the graph is switched/started like you do is correct, otherwise erased since if variables are set before, they are just set on the original graph which in runtime is not serialized and therefore those variables do not persist when an instance of that original graph is created when using SwitchBehaviour.

With that said here is what I just tried:

1) I created a gameobject with an FSMOwner attached, but no FSM assigned.
2) I created an FSM asset graph.
3) I used this code (attached on the FSMOwner gameobject):

In runtime the FSMOwner is switched to use the FSM asset and the manual variable set is there and visible in the graph editor view.
Please note that I have used “Start” here. If I was to use “Awake” or “OnEnable”, then indeed the variable set is not there. That is because the new graph loaded is not yet initialized (which is done in Awake and OnEnable for the FSMOwner and Graph respectively).
The above example code also works correctly in the “Update” method instead of “Start”.

Can you please confirm when you are calling SwitchBehaviour and setting manual variables (Awake, OnEnable, Start, Update), when not using the coroutine workaround? When is your “Load” method called basically 🙂

Thank you.

Join us on Discord: https://discord.gg/97q2Rjh