- Home /
Question by
ojjsaw · Jun 04, 2014 at 06:45 PM ·
nullreferenceexceptionclassserializabledrag objects
Serializable class variables loose Gameobject reference in inspector
// NOTE I DRAG AND DROP game objects from Hierarchy into q and r (before running/PLAY)
[System.Serializable]
public class A : MonoBehaviour
{
[System.Serializable]
public class B
{
public GamObject q;
public GameObject r;
}
public B myclass;
public int temp;
void Awake(){
myClass = new B(); //i will loose q and r reference here?
Debug.Log(myclass.q.name); //NULL reference exception, even though I dragged!
}
}
How will I access the drag/drop game object and not loose the reference - i need it serializable so that things show up in inspector but without loosing game object reference? Please Help!
Comment
Solved!
$$anonymous$$y mistake of doing new i don't actually need to create a new instance! stupid me! it works perfect!
Nice question and nice answer. Can you convert your comment as an answer ?