I’m calling a basic GameObject.Find(“CameraName”) in the start of my script for a prefab that gets instantiated in the scene. When I have the prefab in the scene when I run it, it works fine and finds the camera. but when I instantiate the prefab it can’t find the camera, so its something to do with the instantiation. I’ve never seen this before! any ideas?
The start script runs when the game starts, not when the object prefab is created if I remember correctly.
Instead of putting it in start try putting it in its own function and calling that functions or using a FixedUpdate() method
Yes because when your start function runs, prefab is not instantiated. So make sure when your prefab is instantiated then find your object.
Here is an example how you can find the object:
GameObject spawnerPoint;
void FindSpawnerPoint() {
spawnerPoint = GameObject.FindGameObjectWithTag("HeliSpawner");
}
void Update()
{
if(!spawnerPoint) {
FindSpawnerPoint();
return;
}
}
I think this will solve your problem. Good day.