The struct is very similar to the class, but there are some differences between them:


A class is a reference type. When an object of the class is created, the variable to which the object is assigned holds only a reference to that memory.

A struct is a value type. When a struct is created, the variable to which the struct is assigned holds the struct's actual data. When the struct is assigned to a new variable, it is copied.



  • Variables in structs cannot be initialized (you can’t set the default value)
  • Structs cannot be inherited from other structs or classes.


Creating structs

To create new struct press ‘plus’ button on the right side of Classes & Structs section (as you do this to create the class) and check ‘Struct’ option:

Note: If you can't find this section, check its visibility in the panel 'Hidden script objects' in the bottom of toolbar.


Using structs

Structs are best suited for small data structures that contain primarily data that is not intended to be modified after the struct is created.


For example you can use it for keeping some configuration in Monobehaviour script and be able to edit its values in inspector. Create a struct set the “Serializable” attribute (to show engine that we went this struct will be displayed in inspector):

After compiling you will able to use it as variable:

Or as an array:

Also you don’t need to create constructor for a struct to set its variables when initializing the struct, they will be shown as an arguments:

Render time: 0.05 seconds
136,977 unique visits