Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Get game objects from other scenes

Discussion in 'Editor & General Support' started by MikeCoderMore, May 16, 2016.

  1. MikeCoderMore

    MikeCoderMore

    Joined:
    Sep 22, 2013
    Posts:
    61
    Hi guys do we have a way of getting objects from scenes we are not in, i will be doing this from an editor window so it doesn't need to be at runtime or anything.

    I'm looking for something like below but to return stuff in other scene hierarchies as well as the one I'm in.
    GameObject[] obj = Resources.FindObjectsOfTypeAll(typeof (GameObject)) as GameObject[];

    Thanks.
     
  2. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
  3. MikeCoderMore

    MikeCoderMore

    Joined:
    Sep 22, 2013
    Posts:
    61
    Excellent, thank you :)
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    SceneManager and the likes still mean you have to load the scene before examining the objects in it.

    I recall someone in the past telling me about: InternalEditorUtility.LoadSerializedFileAndForget
    This takes an Object as parameter (load the scene file using AssetDatabase.LoadAssetAtPath) and then pass that object into this method.

    The result is an array of objects that are in that scene, although results may vary from not working to crashing your editor from my personal experience....