Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Scene - Copy game objects from one scene to another

Discussion in 'Wish List' started by tgraupmann, Mar 25, 2009.

  1. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    There is a workaround where you copy scene objects into a prefab to put into a new scene.

    I'd rather be able to copy and paste game objects from the scene into another scene.

    All the references would be intact.

    Even better, I'd like to copy and paste game objects from one project into another project.
     
  2. cyb3rmaniak

    cyb3rmaniak

    Joined:
    Dec 10, 2007
    Posts:
    162
    I use this...
    Code (csharp):
    1. @MenuItem("File/Load Scene [Additive]")
    2. static function Apply ()
    3. {
    4.    var strScenePath : String = EditorUtility.GetAssetPath(Selection.activeObject);
    5.    if (strScenePath == null)
    6.    {
    7.       EditorUtility.DisplayDialog("Select Scene", "You Must Select a Scene first!", "Ok");
    8.       return;
    9.    }
    10.  
    11.    Debug.Log("Opening " + strScenePath + " additively");
    12.    EditorApplication.OpenSceneAdditive(strScenePath);
    13.    return;
    14. }
    15.  
    This is an editor script, so put it in the Editor folder under your Assets folder in order for it to work.
    Just click on a scene file in your project, go to File -> Load Scene [Additive].
    And it will open it without closing the scene you're working on.

    What I do:
    I Save the scene I'm working on.
    Delete all the objects I don't want to copy.
    Load additively the scene I need to copy the objects to.
    Save the scene as the 2nd scene I oppened or under a new name.
    Done.
     
  3. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Code (csharp):
    1. EditorApplication.OpenSceneAdditive(strScenePath);
    Is there a way to iterate through the objects in your additive scene so you could have a confirm box?

    With a confirm box, you could check the imported assets like importing a package.

    Maybe even rename game objects as you import them.
     
  4. cyb3rmaniak

    cyb3rmaniak

    Joined:
    Dec 10, 2007
    Posts:
    162
    Not that I know of...
    You can maybe keep track of what you had in the scene and use EditorWindow.OnHierarchyChange() to try and enumerate all the new objects that were loaded, and select which ones you want to keep and under what name. It will still load the entire scene though.

    This deserves to be on the wish list.
    Just wanted to save you some time until something like this is actually implemented :D
     
  5. DaveA

    DaveA

    Joined:
    Apr 15, 2009
    Posts:
    310
    Amen, I wish this too. Actually, I find it nearly impossible to work on a scene with anyone else. If two or more people are collaborating, you are pretty hosed.

    There must be a way to get an editor script serialize a tree out to, say, xml, and then import it back in, no?
     
  6. kino

    kino

    Joined:
    May 6, 2010
    Posts:
    2
    Here's an updated javascript version that works in Unity 2.6.1 Indie on Windows:

    Code (csharp):
    1. @MenuItem("File/Load Scene [Additive]")
    2. static function Apply ()
    3. {
    4.    var strScenePath : String = AssetDatabase.GetAssetPath(Selection.activeObject);
    5.    if (strScenePath == null)
    6.    {
    7.       EditorUtility.DisplayDialog("Select Scene", "You Must Select a Scene first!", "Ok");
    8.       return;
    9.    }
    10.  
    11.    Debug.Log("Opening " + strScenePath + " additively");
    12.    EditorApplication.OpenSceneAdditive(strScenePath);
    13.    return;
    14. }
     
  7. mdenton

    mdenton

    Joined:
    Feb 13, 2012
    Posts:
    2
    2 years later and this still isn't a thing. How can a professional Game Engine not let you import assets from one scene to another? It's still a huge pain to work on the same scene with someone else. I appreciate you guys patching their shoddy work at least.
     
  8. NTDC-DEV

    NTDC-DEV

    Joined:
    Jul 22, 2010
    Posts:
    593
    This been working for long long while (> 2 years) now. Open Scene1; Select GO's; Copy / CTRL+C; Open Scene2; Paste/CTRL+V;
     
    Quangvn likes this.
  9. nickz

    nickz

    Joined:
    Nov 2, 2007
    Posts:
    43
    Any idea how to transfer game objects from the hierarchy of one scene to another, but in different projects? This would mean that all dependencies would get copied as well. Thanks.
     
  10. Metron

    Metron

    Joined:
    Aug 24, 2009
    Posts:
    1,137
    I think the best solution would be to put those objects into a prefab, export the prefab on one side into a unitypackage and reimport it in the new project.
     
  11. nickz

    nickz

    Joined:
    Nov 2, 2007
    Posts:
    43
    This is actually what I'm trying now and seems to be working good enough. Thank you for your reply.