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:
- Go to your desired class
- 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”)
- Declare the PlayerStats using the following syntax:
Your header file should be similar to the image below:
Now, in your source file you can type for example: