A structs is a custom variable which you can create. Think of structs as containers, which are constituted by different data types.

Creating a Struct

In order to add a struct, from the class wizard check the “Show all Classes” and select the class Object (I named my stuct PlayerStats in this case). When visual studio pops up, delete the UCLASS() along with all it’s contents and create your struct using the following syntax:

Note that I’ve commented out all the lines of code which need to be deleted. Note that you must declare every property you want to have in the editor as UPROPERTY.

Also, don’t forget to include the Engine/DataTable.h header file right before the .generated.h.

Consuming a Struct

If you want to use the Struct I made above:

  1. Go to your desired class
  2. Before the “NameOfYourActor.generated.h” header include the corresponding header file for your struct (if you used the same name as mine it will be “PlayerStats.h”)
  3. Declare the PlayerStats using the following syntax:

FPlayerStats Stats;

Your header file should be similar to the image below:

structs_header

Now, in your source file you can type for example:

int32 x=Stats.XpToLevel;

Share postShare on Facebook0Tweet about this on TwitterShare on LinkedIn0Share on Reddit0