What is best practise for Wait States

Andy Buchanan 4 years ago updated by NeedsLoomis 4 years ago 23

Say I would like to transition from one state to another after a random duration, but a duration decided within that state, what is the best way to achieve this? 

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Satisfaction mark by Andy Buchanan 4 years ago

You mean something like this?

Ah yes thanks!, exactly that. How does it determine which transition to trigger if there are several? Can it? Maybe not an issue as the current case I'm looking at only has one.

You would drag out more transitions to the other state and in those transitions you would have your code.


That's where I wanted to go, but the timeout value is calculated in the Flow State not the Transition states and I can't see a way to pass the value safely, if I make it a graph variable in the flow state it's not available outside (that I could see) and if I make it an object variable it could ( and indeed will in one of my current test scenes ) conflict with variables in other state machines running on the object. Hoping I've missed an obvious trick here :-) 

EDIT: My specific concern is where the transitions point at different nodes - which node would be transitioned to by the internally generated transition event?


You can put it in the transition state.

How? If the value has been calculated in the original state, how do I pass it to the Transition states safely please?

At the moment I'm thinking maybe I have to do it with Custom Events?

Use get/set variable in the transition or final state.

Pending Review

The intended way would be to store the calculated time in an object variable indeed. Is there no way for you to avoid your name conflict?


I'm trying to avoid using an object variable as it could conflict if I run multiple copies of the machine on the same object. Maybe this is not a typical use case for the Bolt paradigm.  

Indeed, the system isn't really planned to support multiple machines with the same graph in them. Can you give me a bit more info about the context here? Maybe I can help you figure out an alternate solution.

Maybe I can construct variable names from strings or something. I had hoped you might have a variable type that was for current "graph stack" or something similar for passing values between graphs. I'm not sure how often I'll need to do this, but it's in my tests ( originally PM tests ). 


What you're looking for is a "machine scope" for variables, if I understand correctly.

I can see the usefulness, but I'm not sure it would be used often enough to justify

a) The implementation time 

b) The added complexity for newcomers (5 variable scopes is already a lot!)

I think I'll just redesign to avoid this. Thanks. :-)


You you can create a custom event with 1 argument as the value. Put this in the transition event. Fire that event anytime you want to pass that value to the transition. Make sure the trigger has the same argument. Much easier this way. 


That's clever, but I think Andy would have the same problem as before; event targetting is at the game object level, so if he has two machines on the same object, both events would trigger at once.

Yes, I tried this. I think reformulating my design is the best option.

True, something I'm working on too for my while loop, but perhaps you could have an Id int value at object level and one at Graph level. On start, feed next one as the I'd value and up the Id on the object by one. Then feed the event as a formula. A string plus B I'd. Perhaps something along these lines? 


I think that sort of thing would work, but at that point the complexity hits the point where a higher level reformulation will probably be cleaner and probably easier to sort out.


I created an idea for machine scoped variables to keep it in mind for the future:


For now, I'll consider this current thread answered.

Hi Andy, I would love to know a real world example of what you are wishing to achieve. I understand it, but with an example I could understand it more.

If you know the order in which the states are saving their variables, you could use a list.