Hi all,
Probably this is a rather silly question, but I’m new in scripting…
I have a multiple states, for the character and I want to put them all in “enum”. Speaking of performance and optimization, which by your opinion is better, making a single “enum” containing all 50 states or making a “class” containing 5 "enum"s, each containing 10 states. If some one ask, why I want to use “class” with "enum"s instead of simply using several "enum"s, I just want to specify different categories and subcategories (for example: class Movement/ enum Walk/ States).
Your answer lies somewhere in the middle. are all 50 states in the same state set? If not, then you will want to create a class of static states then use those throughout your code.
I do not believe either option is more “optimized” as they are just numbers.
both of these will be as fast as you need them to be.
Make what feels more functional from the standpoint that you need to work with these things.
Due to visibility issues of state transitions, use a single enum with good naming convention. Though with 50 states you will probably end up tieing yourself in knots. I assume these are more animation states than actual AI states so you may want to look at other options. If you are using these states for AI you may want to simplify your states to as few as possible (just trust me on this), your state graph will look like a plate of spaghetti and you will be overwhelmed by rapidly growing inherent complexity.
Can you give us more details on what problem you are trying to solve so we can offer some more suggestions.
You forgot to mention that he would need to create a Coroutine for something or other.
I think the route you take will be more a function of organising them in a way that you can easily find the state you want. I don’t think either way will have an impact on performance.
I would agree that it will behoove you to make sure you really need that many states. Remember that a state machine usually has a function or routine that goes with each state, and fifty of them can get unmanageable quite easily. If you can find two states that are doing the same thing, merge them and use one function. And yes, good naming conventions are important even for small sets - they become vitally necessary for something this large.
Thanks for all opinions, I just wasn’t sure if multiple sub-classes will have any impact on the performance.
These are all imaginary states, that I assume, the character can be in, including all movment states, like walk, jump, run… through all the shooting, intaractions, abilities usage… etc. Based on thеse, I will build severel swich statements, with all the methods needed to visualise the different states.
And I came to decision, instead of making sub-classes in one file, just to make severel files for each set of states ![]()