Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

When to use a struct in ue4?


Asked by Allan Carlson on Dec 12, 2021 FAQ



In UE4, structs should be used for simple data type combining and data management purposes. For complex interactions with the game world, you should make a UObject or AActor subclass instead.
Besides,
Structs enable you to create custom variable types to organize your data, by relating other C++ or UE4 C++ data types to each other. The power of structs is extreme organization as well as the ability to have functions for internal data type operations.
And, A Transform struct holds Location (a Vector struct), Rotation (a Rotator struct), and Scale (a Vector struct) data about an Actor. You add a struct variable to your Blueprint in the same way you add any other Blueprint variable. Simple structs, like Vectors, Rotators, and Transforms, are listed in the top section of the variable type dropdown menu.
In respect to this,
Marking the USTRUCT as BlueprintType and adding EditAnywhere, BlueprintReadWrite, Category = "Your Category" to USTRUCT properties causes UE4 to automatically create Make and Break Blueprint functions, allowing to construct or extract data from the custom USTRUCT. Special thanks to Community member Iniside for pointing this out. :)
In fact,
A struct is a data structure that stores data elements belonging to different types. Whereas an array stores data elements of a similar type, a struct stores data elements of different types. A struct should be used when the data elements are not expected to change value.