![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | tyo |
Apologies if this is an inappropriate category/question for this category.
I’m curious how some of you guys manage your state machine variables shared across different states, particularly for a character? For example, velocity is something you might want to have several states mess with, so how do you allow those states to mess with that variable?
To be clear, I don’t mean for the new animation state machine, I’m talking about the state machine design pattern as it applies to godot.
Currently, I just have all those kinds of values stored in the “oldest parent” of the hierarchy so to speak, and all my states reference that parent to read or modify any desirable variable. I was thinking about using some sort of singleton to store it, as that script is getting quite cluttered… Hoping I can get some insight into how to organize some of this data better, really.
I’m working in GDscript currently, but if it would be smarter to do this sort of thing in C# or C++ I’m comfortable with implementing it in one of those to achieve what I want to achieve in some better way.
Thanks!
I think there is an underlying assumption that I want to ask about. Are your states in your state machine individual nodes?
iron_weasel | 2019-04-26 17:22
Indeed they are.
tyo | 2019-04-26 18:24
Hmm, I do it a totally different way. I build my states out of a combinations of functions and little wrapper objects. Common variables are just part of my player script. State specific variables are usually just part of the functions (which are co-routines). And any variables required for smooth transition are stored in the little wrapper objects.
I wonder if I should post a tutorial.
iron_weasel | 2019-04-27 17:11