Missing Component Exception. Can't find a component that exists.

I have a car in my Resources folder that get loaded like so.

Instantiate(Resources.Load("Car", typeof(GameObject))) as GameObject;

And in that Car is a left and right taillight gameObject with just a light attached…
In a script attached to the car I call this line:

left_light = GameObject.Find("Left_Taillight").GetComponent<Light>();

in Awake() and this in Update()

left_light.enabled = true;

I get the error

MissingComponentException: There is no 'Light' attached to the "Left_Taillight" game object, but a script is trying to access it.
You probably need to add a Light to the game object "Left_Taillight". Or your script needs to check if the component is attached before using it.

So I imagine it is the “Or your script needs to check if the component is attached before using it.” because I know there is a Light attached to that object. How can I check if the light exists first?
Does my car get loaded into the game bit by bit so it can actually have scripts running before the Light component has been attached to the gameobject (And that’s where the error comes from)?


Find doesn’t seem to look for child GameObject’s. Search for for the leftlight within your hirarchy by supplying it, or search for the GameObject in a different way.

left_light = GameObject.Find("Car/Left_Taillight").GetComponent<Light>();

Also be sure that the Car actually is named “Car” in the scene. instantiating will usually name it “Car (Clone)” by default

Personally, I would actually check through the cars children and add them to a list. if the left light needs to change based on a button, you could have a shared bool value for logic and showing. Realistically, there’s no moment which that car needs to be setup in the same script. you can tell the car to make the connections when created. Maybe I’m just looking too far into it. I’m sorry.