- Home /
Gameobject missing camera when instance prefab
Hy guys 've a gameobject with declared Camera:
public camera Cam;
When my gamebject drag into prefab, and after it instance from game manager, this instance prefab missing Cam;
How can fix this?
Thank you
Answer by Magso · Jan 07, 2019 at 01:09 AM
If the camera is a separate object it will loose the reference. Either parent the camera to the prefab or find the camera in the scene.
GameObject.Find("Camera");
//or
GameObject.FindWithTag("MainCamera");
Answer by mustang4484 · Jan 08, 2019 at 05:09 PM
hello
I've try with both:
cam = GameObject.FindWithTag("Maincamera"); cam= GameObject.Find("Camera");
But it's impossibile to convert from unityengine. gameobject to unityenginecamera;
Sorry I thought it was a gameobject variable. To get the camera component
GameObject.Find("The gameobject name of the camera").GetComponent<Camera>();
//or
GameObject.FindWithTag("The gameobject tag of the camera").GetComponent<Camera>();
when ever you're using component variables/references add the
...GetComponent<NameOfComponent>()...
Answer by Kaloid · Jan 08, 2019 at 07:44 PM
How is your prefab structured? That would tell us a lot. Can you include a screenshot of the prefab from the editor hierarchy window?
Your answer
Follow this Question
Related Questions
how to destroy camera instatiated from prefab? 0 Answers
Howto set main.camera as a parent when main.camera itself is a child of a prefab 1 Answer
changing a bool in a prefab doesn't change in it's instance. 2 Answers
Instantiating prefab camera 2 Answers
Clicking one prefab effects them all. 2 Answers