- Home /
How to create GameObject without adding it to scene?
Hey. I have a prefab with Monster class and a list of monsters. I want to fill this list with instances of this prefab. How do I do that? Monster.Instantiate will create instances of monsters in the scene, I just want to have this list to access at a later time. I've read I shouldn't create MonoBehaviour instances of class via new Class() constructor. I could just set location of these prefabs to place them somewhere far away from game scene, but it doesn't seem to be good solution.
Answer by 767_2 · Sep 27, 2014 at 07:09 PM
make prefabs out of other monsters too and add them to your list via inspector , click at the monster class prefab and a list will be in the inspector drag and drop other prefabs in it or use gameObject.SetActive(false);
What if the script containing this list isn't a $$anonymous$$onoBehaviour. It's a static class, I can't attach it to any GameObject in scene to add List elements via inspector. Also it's not what I was asking for, I want to instantiate n (variable) monsters in code, without adding them to scene. Is there a way to istantiate them and "hide" from game view?
yes you can gameObject.SetActive(false);
will disable and hide them
you can Instantiate then use SetActive(false) to hide in scene.
and Louis Watson just agrees with me what can be better ,right louis
haha sorry couldn't see your post when I commented ;) other alternative would be to store the path string of the asset rather than the Prefab itself and use AssetDatabase to load it. All the info is in the documentation :)