Here is what I’m doing (Shorter version :D)
- I’ve created an empty serializable class with only a public integer variable “myNumber” inside it.
- I then create an instance “A” of the serializable class. copy “A” to a new variable “B”.
- in the editor set the variable “myNumber” inside “A” and see what happen to “myNumber” in “B”.
- in the editor set the variable “myNumber” inside “B” and see what happen to “myNumber” in “A”.
##Well, what happen is that when you change “B” then “A” changes as well, so they seem to point to the same variable.
##But when you change “A” nothing happens, not even “A” changes.
What’s going on with the Serializable class ?
Why only B can be changed ?
Any explanation would be really welcome !
So here are the scripts :
// caller script attached to a game object and used to instantiate my serializable classe
using UnityEngine;
public class TestClassCaller : MonoBehaviour {
public TestClassSerializable serializableA, serializableB;
void Start () {
serializableA = new TestClassSerializable();
serializableB = serializableA;
}
}
// Serializable class
[System.Serializable]
public class TestClassSerializable {
public int myNumber;
}