NodeCanvas Forums › General Discussion › Using FSM for UI flow: Back button trouble
Hi!
I want to use a FSM for UI flow: Each screen is a state.
Now I also need a back button functionality.
Currently, I got a BBVar (bool) wantsBack.
Each state connects back to the “calling state” and checks if wantsBack is true.
So far so good?
My problem is:
As soon as I enter the “back state”, since wantsBack is still true, it steps back again and again and again.
I have to set wantsBack to false in every OnEnter of every state.
Is this the suggested solution?
If I use Unity states (Mechanim), there’s the concept of a Trigger, which automatically resets, once consumed.
Is there something like this in Node Canvas or am I missing something?
Thanks!
Short update:
One current solution would be to use this transition code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
namespace ModernAlchemists { [Category( "Modern Alchemists" )] [Description( "Consumes a bool" )] public class TransitionTrigger : ConditionTask { public BBParameter<bool> trigger; protected override string info { get { if( trigger != null && !trigger.isNull && trigger.name != "" ) { return string.Format( "Trigger:" + trigger.name ); } return string.Format( "Assign BBVar first." ); } } protected override bool OnCheck() { if( trigger.value ) { trigger.value = false; return true; } return false; } } } |
Please note that the string info part isn’t working yet. It always prints “Trigger:”, even if the name is empty.
Hello,
I like your solution as well as the condition 🙂 I think I will include this in the next version as well. The name property by the way, can be made easier, since BBParameter already overrides ToString(), thus to return a nice label automatically 🙂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
namespace NodeCanvas.Tasks.Conditions{ [Category("✫ Blackboard")] [Description("Check if a boolean variable is true and if so, it is immediately reset to false.")] public class CheckBooleanTrigger : ConditionTask{ [BlackboardOnly] public BBParameter<bool> trigger; protected override string info{ get {return string.Format("Trigger {0}", trigger);} } protected override bool OnCheck(){ if (trigger.value){ trigger.value = false; return true; } return false; } } } |
With that said though, I think that if you want to actually check if a button is clicked, then maybe using the “UGUI/Button Clicked” condition could be a better option depending on your use case.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh