Custom classes behave like structs - Clarify
Hey. Unity states that "custom classes behave like structs" (1) (2). I have understood (and not thought much more about) the premise that Unity can serialize references to Unity.Object derived classes, and that custom classes are serialized as only their values. However, I now question my understanding since I can only imagine this scenario happening while in Play Mode.
For example, using their example:
[Serializable]
class Animal
{
public string name;
}
class MyScript : MonoBehaviour
{
public Animal[] animals;
}
If you populate the animals array with three references to a single Animal object, in the serializationstream you will find 3 objects.
How could I populate that array with a single Animal object outside of Play Mode? If I were to use the inspector and set the array size to 3, this would automatically create 3 different objects. I can't imagine a way to populate that array with the same custom object without being in play mode. In fact, I can't think of a way to populate any field with the same custom class without being in play mode.
Can you clarify what they mean with a practical example?
Thanks.
Your answer
Follow this Question
Related Questions
ISerializationCallbackReceiver - total confusion or simply unstable? 0 Answers
Why is my serialized custom class/struct not properly instantiated (values return null/default) ? 0 Answers
How Can I Stop my Array Being Cleared on Runtime via Serialisation? 0 Answers
Understanding the need of serialization 1 Answer
Binary Serialization problem. 1 Answer