Copying structures
Structures of the same type can be copied entirely into each other using the '=' assignment operator. Let's demonstrate this rule using an example of the structure Result. We get the first instance of r from the calculate function.
void OnStart()
|
Then, the variable Result r2 was additionally created, and the contents of the r variable, all fields concurrently, were duplicated into it. The accuracy of the operation can be verified by outputting to the log using the method print (the lines are given in the comments).
It should be noted that defining two types of structures with the same set of fields does not make the two types the same. It is not possible to assign a structure to another one completely, only memberwise assignment is permitted in such cases.
A little later, we'll talk about structure inheritance, which will give you more options for copying. The fact is that copying works not only between structures of the same type but also between related types. However, there are important nuances, which we will cover in the Layout and inheritance of structures section.