- Home /
Question by
Lord_D1as · May 20, 2019 at 01:50 PM ·
unity 5gameobjectprefabreference
Reference missing in runtime
I lose a reference of a gameObject when I start a game. I've tried GetComponent<>(), GameObject.Find() and Resources.Load(), but nothing works.
capture2.jpg
(26.6 kB)
capture3.jpg
(13.6 kB)
Comment
Answer by Legend_Bacon · May 20, 2019 at 01:59 PM
Hello there,
I would start by changing a few things in your scripts. For your purpose, it would probably end up more like this:
public GameObject light = null;
private void Start()
{
if(!light)
{
Debug.LogWarning("GameObject light is not assigned!");
light = gameObject;
}
}
Please note that for GameObjects you shouldn't be using GetComponent(). the gameObject property will already return the GameObject your script is attached to.
Hope that helps!
Cheers,
~LegendBacon