0
Answered

Enum Literal?

fotoshopt 3 years ago updated by JasonJonesLASM 3 years ago 8

I have the following graph in a state transition


The object variable "Objective" is an enum.

On enter state, I would like to evaluate the current value of "Objective", and if it's of a certain value, transition to the next state.

I figured out that I could just specify a graph value on each state transition (an instance of Objective), and compare the Object value to the Graph value, but since each transition requires it's own value, an Enum Literal would be preferable (but it doesn't seem to exist).

So instead of creating a single graph variable on each transition graph, I could just specify the enum value I would like to check against within the graph.

Possible?

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
+1

Have you tried the "Switch On Integer" Node ? Or "Switch On Enum" ?

Thanks for the response. 

I'm not sure how a switch on int unit would help in this instance (would 0 represent the first enum value?), and I do not see a switch on enum. Is there something I have to do to expose that unit?

+2

It is in the same list where "Switch On Integer" is:

Ah! When you fuzzy find "Switch" or "Enum", nothing shows up. Looks like you have to navigate the unit menu Control->Switch on Enum.

I found it, used it, and it works. Thanks!

+1
Answered

Enum literals don't exist as such (abstractly), but they exist for each enum (for example, a "Objective Literal", if your enum is called "Objective"). I'll look into the Switch not appearing in the search results!

+1

@fotoshopt I just purchased Bolt in the May sale and was looking at this same issue; make sure your enum Objectives is marked as Serializable. This allows the Unit Database to properly present it as a literal.

I have ported some code from c# to bolt...

The only code that is left is an enum...

Might be nice to be able to define enums inside of bolt  to get rid of all source code 

I realize they would have to be generated and exported at some point to work with external code...

I also realize this is stupid and pointless but would be nice to get rid of ALL code and be self contained

I also realize this could would and should never work

Thanks

+1

There is many ways this could and wouldn't work. You can develop a new type that is a fake enum and is a macro. Macros can persist in and out if editor. But building a true enum without code to back it up might be much trickier, but maybe possible?. Something with the Options part of the API (how variables get populated in the finder), also would need new units for this new fake type, like a new literal, switch, ect. That's my thoughts from my knowledge anyways. For now you can download my enum generator, and not even worry about the scripts it generates. As of now they are hidden in a generated folder and auto global namespace. So pretty much automatic, and you just stick to bolt.