Child script's static instance becomes NULL when a parent script reloads?

I have two scripts: A and B.

  • Script B is attached to a child GameObject of script A’s GameObject.
  • Script B has a static instance referencing its parent GameObject.
  • Script A references B’s static instance.
  • Script B’s static instance is set in its Awake() as such:

function Awake() {
instance = this;
}

When script A is reloaded due to an edit (while my Scene is running), it throws a NullReferenceException when it accesses script B’s static instance.

I’ve checked and B’s Awake() is not called a 2nd time.

I think it’s loosing the reference because static variables aren’t serialized out during assembly reloads. There is a megapost about these issues here:
http://forum.unity3d.com/threads/155352-Serialization-Best-Practices-Megapost

It’s mostly about editor side stuff but I think it also applies in your situation.

Thanks.

My use of static instances is very standard and my project is currently small. Most people must not put their statics within a hierarchy like I have.