- Home /
hi, I have public Gameobject,added via inspector when i move out from location(scene) and come back,the public is not there anymore, i cant use Gameobject.Find since its inactive.
i tried to make "active manager" and have all objects that dont need to be in game from beggining underneath and instead of setting it active underneath desired gameobject i changed its parent while keeping it activated.but its not working..is this what static private get set is for? thanks.
Answer by Gordrik · Apr 06, 2018 at 08:30 AM
Using find is a bad idea, cause it is searching whole scene for an object, which is expensive, and yes, it can't find inactive objects.
What you could do is creating an empty, make it singleton, put in to it inactive objects, and get access to them by using .instance.GetComponentInChildren();
the story goes like this, i have a gameobject called quests(disabled unitl you open it obvoiusly), its a 2d screen with gridlayout,with a bunch of Texts.all disabled from the begining. if i go and talk with npc , it says in one of the dialogue options,. gameobject.find "quest1".setactive.true , that of course doesnt work. i am not yet familiar with singletons and instance, so i'll take a look.
singletons are quite basic, and make accessing a class much easier, but use it only on classes like managers where you have only one on whole scene, or even game.
This looks well explained: https://www.youtube.com/watch?v=CP$$anonymous$$Agyp8cno
Your answer
Follow this Question
Related Questions
How to assign a gameobject to a script that is added dynamically 1 Answer
How to make a public game object array inside an array (or 2D array) that can drag and drop to fill? 1 Answer
Why is text ui cant be static ? 0 Answers
Unity 5 And Attaching Game Objects To Inactive Objects 1 Answer
Possible to make GameObject.GetComponentInChildren() check inactive objects? 3 Answers