I'm using the new SceneManager to load multiple scenes in the same structure adopting the Additive method. I find it extremely useful but I wonder if there is a way to get all the GameObjects for a specific scene. When multiple scenes are loaded I see the GameObjects clearly separated by scene in the hierarchy but I cannot find a way to access the specific hierarchy of a single scene via script. Is that possible? The findGameObject method I think returns the GameObjects for all the scenes..
1 Answer
\$\begingroup\$
\$\endgroup\$
1
You can get all the root Game Objects of a specific scene using SceneManagenent
, that will return an array of GameObject
.
GameObject[] _rootGameObjectsOfSpecificScene = SceneManager.GetSceneByName("YOUR_SCENE_NAME").GetRootGameObjects();
Replace YOUR_SCENE_NAME
with your scene name.
-
\$\begingroup\$ What version did this show up in? It doesn't appear to exist in 5.3.1. \$\endgroup\$– Almo ♦Commented May 7, 2016 at 20:13