Is is possible to add variables to/under enums? I’m trying to make a way to place objects in a grid through the construction script. I’m using enums to get which object to place but I would also like under each object a way to position it, so variables under each enum. Let me know if I’m not explaining it in a nice way.
So basically there would be a array of floats to change under each enum.
I don’t believe you can do Java style enums, but you could always have a lookup function that returns an object or struct depending on the enum passed to it.
Might be easier to do this in a more data-oriented way, like a CSV file or something.
If you’re dead set on an enum, I really think the best option you have in Blueprints is a function that takes a room enum value (Room1) and returns a struct holding the information you need. ({ OffsetX: 1, OffsetY: 4 })
Or… Are there maps/dictionaries available in Blueprints? You could have a dictionary, set each enum entry as the key, and the information you need as the value. Again you’ll want a wrapper struct.
If the location data isn’t inherently tied to the Enum (i.e. you want to store a variable which contains “ObjectName, World Location”, rather than selecting “ObjectName” and having that ObjectName always be tied to a specific location) I would create a Struct.
A Struct is essentially a variable made of variables (the classic example being Epic’s Hit Struct, which contains a bevy of info like location, actor, component, bone name, impact normal, surface normal, etc.) Yours would be made of two variables:
(1) an Enum (or Name, or whatever) which stores the type of object, and
(2) a Vector, which stores its location in world space
To change any of the values of the Struct, you would use a MakeStruct node to set each individual value, and then use a Set node to set the made Struct to whatever variable
i.e. MakeStruct “Name: Room 4, LocationVector: 650,780,1800” ----> Set PlayerRoomVar.
Though without knowing exactly what you want to achieve it’s tough to recommend a course of action as such.
First, you need to understand Enum. I do not know about other programming language, but in the context of C++, & Blueprint, its like a boolean variable (0=false, 1=true), but you can have more than 2 states (true/false).
Examples
Enum Grade
0=E
1=D
2=C
3=B
4=A
5=A_Plus
Enum TVMode
0=off
1=StandBy
2=On
So in the end of the day, its a variable, & you cannot add variables to a variable.
For that, you will need either a class or a structure.
BP Structure: collection of variables including Enum (which is a variable itself)
BP Class: collection of variables, as well as functions, inclusive constuctor(in the form of contruction script & default values) & destructor (On destroy node).
Class is a bit more complex, but just a rough guide.
Just remember, BP is very similar in implication to programming languages & script like Unrealscript & C++.