Blueprints Make Monoliths

Stay away from blueprint assets for enums and structures!
February 22, 2024

Yes, it is far easier to simply right-click the content browser and select a new enumeration (enum) or structure (struct) for use in what could be a mostly blueprint game…

What NOT to do!

You pay back that simplicity in the long run almost every. single. time. While it may scare a beginner to get there hands dirty in converting their project to c++ for the use of the highly-useful enums and structs, you will thank yourself down the track that you did.

Okay, what are enums and structs anyway?

Enumerations

Where a Boolean sits as either a 0 (false) or 1 (true), think of an enumerator as a longer Boolean where we can have from 0 to UE_BIG_NUMBER, where each value corresponds with a name you’ve given:

This snippet has been stolen from another post on better definitions for enums in UE C++.

In blueprint it would look like this:

RarityType in Unreal Engine 5

Structures

Think of structures as a collection of variables that sit in one big variable. This is very useful for holding data that is only going to be accessed at the same time as the rest of the data. Normally if you want the name of the sword, you are going to be soon using its damage and rarity. So those can go together like so:

In blueprint it would look like this:

Equipment Data in Unreal Engine 5

The solution

If everything else is blueprint then that is okay, just ensure that your structs and enums are in C++, it is a better practice and if you ever end up moving some blueprint code to C++ you’ll be thankful that everything already references the C++ structs and enums. Otherwise you will be due for a ton of replacing references.

Converting blueprint projects to c++ and setting up our variable file

From the level view, navigate to the Tools menu and select New C++ Class:

New C++ Class menu in Unreal Engine 5

Then go to All Classes and select Object, then click Next:

Choose parent c++ class in Unreal Engine 5

Name it what you want, we are only interested in the header file (YourName.h).

Name new C++ class in Unreal Engine 5

Ensure you select Public for ‘Class Type’ and click Create Class. You should be greeted with this:

success naming class in Unreal Engine 5

To build from your IDE you will need Visual Studio Community 2022 (for use in 5.3), follow this link by Epic for that setup.

Navigate to your project folder and double-click the .sln that should now be created:

.sln in Windows 10 explorer

If it isn’t there, right-click your .uproject and select Generate Visual Studio project files:

Generate visual studio project files from Windows 10 explorer

Once your solution is open and loaded, go ahead and open up your NewFile.h from the solution explorer on either your left or right. I am using JetBrains Rider here, the process is still the same.

GlobalVars.h

You can go ahead and delete the:

As we won’t be needing it, now we can get started.

C++ Enum

Go ahead and add a new enum below the #include "YourFile.generated.h" like so:

GlobalVars.h

Ensure you specify BlueprintType in the UENUM() braces, otherwise your enum will not be exposed to blueprint!

Any text in between the ‘/** */’ above any of the enum types will be converted into a description for that type, just like the description in blueprint:

Rarity Type enum descriptions in Unreal Engine 5

To define a description for the whole type, simply put the same kind of comment above the UENUM(BlueprintType) declaration.

C++ Structure

Go ahead and add a new struct below the #include "YourFile.generated.h" and below the ERarityType enum like so:

GlobalVars.h

Once again, we can define descriptions using the ‘/** Your Description Here */’. An important note is to include the:

This is your default constructor and allows blueprint to make the Break Struct and Make Struct nodes like so:

Break and Make equipment data blueprint nodes in Unreal Engine 5

It is also important to include:

Above each variable so that it can be used in blueprint!

The second constructer is not strictly necessary, but is good practice:

This allows for better use in C++ where we can then create an FEquipmentData like this:

Good practice is great idea whether you’ll ever use the type in C++ or not!

NOTE: If you wish to use a struct as a variable in another struct, ensure that the first struct is defined above the one that is trying to reference it (this also goes for enums).

Now, hit Run or Build Solution, and open up your project!

Finishing touches

When you go to add a variable to any blueprint class you’ll see your structure name without the ‘F’ prefix and it should show your custom description as per your code!

C++ equipment data in blueprint in Unreal Engine 5

And for your enum, the engine will show prefix ‘E’ in front of the variable type like so:

c++ rarity type in blueprint in Unreal Engine 5

With our descriptions showing on each selected type for the enum:

C++ rarity type descriptions seen in blueprint in Unreal Engine 5

There, you have setup a better practice for these datatypes in your development!

Billboard summary

Say goodbye to blueprint enums and structs! Gone are the future headaches of not using C++ enums and structs!

1. Add a Object C++ class to your blueprint project

2. Install Visual Studio Community 2022

3. Generate Visual Studio Project Files

4. Open up your new C++ class header file (.h)

5. Delete the class definition, and under the #include "YourFile.generated.h" begin adding the enum and struct definitions of your dreams like so:

6. Build and open your project to have these new types just as accessible as their bad practice blueprint counterparts!

Thanks for Reading!

See if Developd is the right fit for you.

Velit
Voluptatem Nostrum Tenetur
Voluptatum
Saepe Odio Voluptas Et
Velit
Voluptatem Nostrum Tenetur