Download

Adding variables to enums

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. :stuck_out_tongue:

So basically there would be a array of floats to change under each enum.

Thanks

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.

I see what you’re saying but my example is:

\Pick which room
enum: Room1
\Adjusted Int to place room, so each room would have it’s on offset variables.
Offset X: 1
Offset Y: 4

So I’d like the user to select which room, then where to offset it. Then add as many rooms as they’d like.

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.

I’m not dead set on enum, open to better ideas. You’re speak a bit over my head but I’m up for figuring it out.

How would you go about making this struct and allowing the user to change the offsets for each room?

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.

Basically I’d like to have this except under each room is also a vector you can adjust for the offset of each room.

a8941ec802a743e651259e0e8ee47dcdee05b8c3.jpeg

So you can click “+” to add another room, then adjust the offset for each room.

I would say to use a Struct, with an Enum and a Vector, and then to store all of those structs in an array.

As RhythmScript said, use a struct that contains the enum and a vector.

So create your enum for the room type.
enum.png

Then create a new structure that contains one variable of the type of enum you created, and one variable of type vector.
struct.png

Then in your actor class create a variable of the type of structure you created. Click on the array icon next it , and make it editable.
act.png

Then once you place your actor in the world, you can add items to the array.
fba7d9e96eaab493861ceb4524153a20aea4cb6c.png

And then when you want to access the members of the array you do something like:
2d1d7d10256cda1c5701ff6922ec23396d05cb56.png

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++.

You guys are all amazing, I learned a lot and got it working the exact way I needed. And thanks for the step by step MattW.

Is there a way to set a slider range for a Int in a structure?