Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JVLVince · Oct 24, 2017 at 12:17 PM · sceneeditor-scriptinggameobjects

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

89 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges