- Home /
merge scene in the editor
hi. i have 2 scenes in my project. how do i add everything from scene 1 to scene 2?
Answer by frankyboy450 · May 01, 2012 at 10:18 AM
never mind. i figures out how to do it anyway
You can select the content in scene 1 and do a basic copy/paste in scene 2.
I do a copy basic copy/paste as you said, I copy some object from scene 1 to scene 2 but some object lost texture. How can I merge 2 scene into 1 scene
Answer by baroquedub · Oct 01, 2015 at 12:04 PM
For @frankyboy450 and any others who are still confused about how to implement this... (the Unity Script Reference isn't quite as useful as it might be as it only shows part of the script you'll need, and provides no help on where to put it.)
First create an Editor folder in your Assets, if one doesn't already exist. Inside that create a new C# script:
Name the file the same as your class name, for example AddScene.cs
Here's the full code you'll need:
using UnityEngine;
using UnityEditor;
using System.IO;
public class AddScene
{
// Simple script that lets you load the contents of a selected scene
// to your current scene.
[@MenuItem("Example/Load Scene Additive")]
static void Apply()
{
string strScenePath = AssetDatabase.GetAssetPath(Selection.activeObject);
if (strScenePath == null || !strScenePath.Contains(".unity"))
{
EditorUtility.DisplayDialog("Select Scene", "You Must Select a Scene!", "Ok");
EditorApplication.Beep();
return;
}
Debug.Log("Opening " + strScenePath + " additively");
EditorApplication.OpenSceneAdditive(strScenePath);
}
}
Note the use of EditorApplication.OpenSceneAdditive(strScenePath);
as per the answer given above.
What this does is add a new item in your editor: [@MenuItem("Example/Load Scene Additive")]
The above code is straight from the Unity Script Reference (http://docs.unity3d.com/ScriptReference/EditorApplication.OpenSceneAdditive.html)
I found another slightly more elegant implementation on GitHub (https://gist.github.com/AngryAnt/6192566) which places the item under the File menu. 'Combine Scenes' remains greyed out until you select two scenes in your Project window:
using UnityEngine;
using UnityEditor;
using System.IO;
public class AddScene
{
[MenuItem("File/Combine Scenes")]
static void Combine()
{
Object[] objects = Selection.objects;
EditorApplication.SaveCurrentSceneIfUserWantsTo();
EditorApplication.NewScene();
foreach (Object item in objects)
{
EditorApplication.OpenSceneAdditive(AssetDatabase.GetAssetPath(item));
}
}
[MenuItem("File/Combine Scenes", true)]
static bool CanCombine()
{
if (Selection.objects.Length < 2)
{
return false;
}
foreach (Object item in Selection.objects)
{
if (!Path.GetExtension(AssetDatabase.GetAssetPath(item)).ToLower().Equals(".unity"))
{
return false;
}
}
return true;
}
}
I hope that's useful to someone :)
Answer by syclamoth · Apr 03, 2012 at 11:15 PM
In an editor script, use
EditorAppliction.OpenSceneAdditive("Path/To/Scene.unity");
Then, just save normally and the two will have become one!
and how do i do this? where can i make an editor script?
Your answer
Follow this Question
Related Questions
Edit terrain using js 1 Answer
terrain not showing 5 Answers
Disable shadow in the Grass 2D texture Terrain 0 Answers
Curvy Shapes in Unity Terrain editor? 1 Answer
A node in a childnode? 1 Answer