- Home /
Prefabs with prepopulated arrays/list
I have empty GameObjects that work as checkpoints for a prefab. The prefab has List that I would like to be the same for all of the prefabs. When the prefab is inside the scene I can add gameobjects to the list, but when I drag it to create new prefab the array becomes full of empty entries. Is there any way to get this working without scripting?
If I understood right, you want to make a prefab in the project view to have references to object instances in the open scene. This is not allowed as far as I know.
Since anything in the Project view can be referenced & instantiated in a scene or for example be loaded from the Resources-folder, it would create silly situations when you try to instantiate such a prefab into a different scene and it couldn't find the objects it has references to.
Answer by Jeff-Kesselman · May 23, 2014 at 10:46 PM
As others say, it doesn't work that way.
Instead, why don't you find all the waypoints at runtime and construct the list in Start() using either https://docs.unity3d.com/Documentation/ScriptReference/Object.FindObjectsOfType.html
or
https://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html