In my opinion:
Start() and Awake() are not equivalent to the constructor because ExecuteInEditMode + Serialization + closing/reopening Unity will result in calling Start/Awake 2+ times.
I tried multiple things (many of which crashed Unity) until I found out that initializing fields where they are defined seems to work perfectly.
Example:
class EditorObject : MonoBehaviour
{
private void mutate() // callers of this code expect changes to be persistent (e.g. when Unity quits/reopens)
{
mutable_in_editor.Add(1);
}
private void Awake()
{
// mutable_in_editor = new List(); // Bad: overwrites serialized object when Unity is reopened
}
[SerializeField] private List mutable_in_editor = new List(); // Good: initializing a field immediately results in constructor-like behaviour.
}
Trending Articles
More Pages to Explore .....