Use Gameobject.Find function on an object in a new scene, after loading that scene.
Hello, I am having trouble using gameobject.find to find an object in a new scene, after I change scenes. I use this code
SceneManager.LoadScene("newscene");
GameObject background = GameObject.Find("Background");
It returns null. The object "Background" is not located in the previous scene, and should not be. It is an object that starts in the newscene. It is in the heirarchy.
I think that perhaps I need to instantiate the object in code, versus just in the editor?
I think that this is likely a question that has already been answered, but I have searched the internet and nothing I have tried has helped.
Answer by tormentoarmagedoom · Jun 26, 2018 at 11:07 AM
Good day.
the function GameObject.Find can only find Active objects. If it is inactive when the code is executed, will not be found.
You can use GameObject.FindObjectWithTag()
Or make it commence active, find it and then SetActive(false)
Bye!
Your answer
Follow this Question
Related Questions
Revers Object Transfrom using an array problem in UI !! 0 Answers
Hi everyone.need help with this. 1 Answer
Making a Deckbuilder 0 Answers