I stumbled across a very strange behaviour. I received a reference to a RectTransform of an uninstantiated and therefore null gameobject.
I wanted to read the extends from a child RectTransform of a prefab without instantiation. The following code did that:
public static Vector2 GenerateMeasureForMessage (ES_Message message){
RectTransform messageRect = message.transform.GetChild (0).GetComponent<RectTransform> ();
return messageRect.offsetMin - messageRect.offsetMax;
}
the following screenshot shows, that, since I use the “message” prefab directly, all its MonoBehaviour variables are still null.
The next screenshot however shows, that it was still possible for the code or Unity or… to retreive the reference
I stumbles across this, because I moved the code into another static variable, doing the exact same stuff, just relaying the work to another static method and THERE it threw the NullReferenceException.
The weird stuff does not happen in the class that holds the prefabs, it’s already a different class.
I don’t get how this works.


Ahh thanks @tanoshimi, I didn't know you could use the string version of the character.
– Lardalot