- Home /
Get all gameObjects of unloading scene from editor Script
Hi everybody,
I playing around unity editor script and now I have a problem. Since I can get all the object of a prefabs via AssetDatabase. LoadAllAssetAtPath(myScenePath). Then now I trying to get all the gameObjects in side a "Scene". I try to use the same way as I've done with the prefabs, But it's return the error say "Do not use ReadObjectThreaded on scene objects!" ...
Well, I think I have to change way to approach my problem. Then a thinking come to my head, Just go to scene by scene and get object by object. hmm it's sound able. Then I try with this code:
for (int i = 0; i < resourcePath.Length; i++){
string s = resourcePath[i];
List<Transform> trans = new List<Transform>();
Debug.Log("count: " + resourcePath.Length + " path: " + s);
Scene scene = SceneManager.GetSceneByPath(s);
if (!scene.IsValid())
continue;
GameObject[] roots = scene.GetRootGameObjects();
foreach (GameObject root in roots){
trans.Add(root.transform);
if (GetAllChildOfTransform(root.transform) == null)
continue;
trans.AddRange(GetAllChildOfTransform(root.transform));
}
m_someTest = trans.Cast<Object>().ToArray();
Debug.Log("scene name: " + scene.name + " count list: " + trans.Count);
}
Then I face the problem here. the valid flag only give me true value when the scene I get in the above script is the scene I opening. Else, it's always false. And the elements of transform list I got will be null when I open other scene after I got them. I try all days just to find out something but seem no hope
I want to know is there anyway to store all objects from all scene instead unloading scene by editor script?
Does my approach wrong or something wrong in my thinking and understand about unity scene object.
Please teach me. Thanks
Your answer
Follow this Question
Related Questions
How can i find out how much element on scene now? 1 Answer
How can I delete the Main Camera using a script? 1 Answer
How to generate objects from a script in the editor, i.e. before runtime? 1 Answer
Scene load crashes iPod 4th gen but not iPhone 4 or 3GS 0 Answers
How to get all GameObjects in Scene? 7 Answers