I’m using a custom network layer to synchronize state from a ‘master’ application running a FSM to a ‘slave’ application on another device. Both apps are using the same FSM to streamline development. I’m able to sync the current active ‘state’ of the FSM to the slave with no problem. I’m using FSMOwner.TriggerState to set the correct FSM state directly on the slave. Because it’s the same codebase, the normal transitions are still active on the slave however. Is there a good way to prevent the FSM from following transitions? I would prefer to not have to remove any transitions from the FSM in the codebranch for the slave devices.
Hmm. Considering I understood correctly, maybe you could instead of removing transitions, disable the FSMOwner altogether in the slave devices and as such any TriggerState calls will result in nothing being triggered since the FSM is not Running.
Let me know if that would work for what you are after.
the use-case is to be able to trigger state of the FSM actively but beeing able to disable the defined transitions for each state of the FSM.
I already thought about including a boolean flag on each transition which needs to be true for following the transition. This would work where I have defined cinditions, but wouldn’t help with “OnFinished” transitions – which would then trigger to early on the master device.
Is there a way to remove transitions from a state in code at runtime?
Yes, it is quite possible to remove transitions or otherwise alter the graph in runtime.
Here is an example code to remove all transitions from a graph assigned to a GraphOwner:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
usingUnityEngine;
usingNodeCanvas.Framework;
publicclassRemoveTransitions:MonoBehaviour{
voidStart(){
varowner=GetComponent<GraphOwner>();
vargraph=owner.graph;
foreach(varnode ingraph.allNodes){
foreach(varconnection innode.outConnections.ToArray()){//must use .ToArray()
graph.RemoveConnection(connection);
}
}
}
}
Let me know if that works for you.
Thanks.
Join us on Discord: https://discord.gg/97q2Rjh
Author
Posts
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Login
Register
By registering on this website you agree to our Privacy Policy.