duplicate scene exactly into another during runtime..

hello,

what is the best way to duplicate one scene into another through code?

in my project i have two scenes on the first scene on play everything is instantiated some things are random, i would like to thus copy these contents into another scene… but as i can see there is not a method to do so… so there must be some workaround…

I’m sort of unclear what you’re trying to do. However, at runtime, I don’t think you’ll be able to make a fresh scene that wasn’t already in the build, i.e., have it report as a separately-named scene name, and at runtime you can’t write a scene file obviously.

To get the same function, you can crawl the hierarchy of root GameObjects in a given scene and clone any or all of them yourself. It helps if everything is under a single GameObject, because then you can just say “Instantiate” on a reference to that one and everything will be copied. There may be subtle details as to how inter- and intra-object links and references are copied, but you’d have to try it first.

Keep in mind ALL cloned objects go into the active scene, not a separate new scene.

Can you take a step back and explain what you’re trying to do, rather than asking about your attempted solution?

hi sorry for the lack of info here is a video to explain more…

btw between the two runs it doesnt show in the video but i went to build settings and activated the scene in build at index 1

so the idea is that i am trying to create a seperate physics scene… thus i would like all objects in scene 0 to be present in scene 1, exactly as they are in scene 0… as you can see on the second play a duplicate scene in created except all objects are instantiated in scene 0… i need them in scene 1…

here is the code i use to load the physics scene

using UnityEngine;
using UnityEngine.SceneManagement;

public class PhysicsSceneLoader : MonoBehaviour
{

    //Exposed to inspector
    public string physicsSceneName;
    public float physicsSceneTimeScale = 1;
    private PhysicsScene physicsScene;
  
    private void Start()
    {
        //load the scene to place in a local physics scene.
        LoadSceneParameters param = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.Physics3D);
        Scene scene = SceneManager.LoadScene(physicsSceneName, param);
        //Get the scene's physics scene.
        physicsScene = scene.GetPhysicsScene();
    }
      
    private void FixedUpdate()
    {
        //Simulate the scene on FixedUpdate.
        if (physicsScene != null)
        {
            physicsScene.Simulate(Time.fixedDeltaTime * physicsSceneTimeScale);
        }
    }
}

im thinking that possibly fixing the code in start… or maybe i would have to execute this script last so the 2 sets of objects are not in the same scene…

but the thing is is that here i am instantiating twice, what i would like to do is instantiate once in the main scene and thus copy everything in the first to the second… i know that there is a movetoscene function… which i can possibly use… so maybe i can somehow dulicate what is created in the scipts and thus move the duplicate to the other scene…

finally i would like to ask if it is possible to make changes in one scene and have it happen exactly in the other scene?
if so how?

any thoughts are welcome…

thanks