Search Unity

Question Clone scene via script

Discussion in 'Editor & General Support' started by xtdiwd, Jun 28, 2022.

  1. xtdiwd

    xtdiwd

    Joined:
    Jul 25, 2020
    Posts:
    135
    Premise: I know some of you will say to use template scenes but I couldn't do it.

    I created a script that adds to the context menu the ability to copy a scene where I have inserted the objects I always use. Only the body of the method is missing.
    I have already tried two methods to copy the scene as a file and also CreateAsset.
    What do I need to write in the method for a new scene to appear where I called the script from context menu with name "your new scene" already in edit mode? Similar to when I create an empty scene from Create/Scene.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    Why not just additively load those from a shared scene and have them hook themselves up appropriately. That's always going to be better than putting a bunch of boilerplate in 17 different scenes, then finding there's an error and you have to change it 17 different times.

    Additive scene loading is one possible solution:

    https://forum.unity.com/threads/right-way-for-performance-divide-scene.1023673/#post-6630961
    https://forum.unity.com/threads/right-way-for-performance-divide-scene.1023673/#post-6754330

    https://forum.unity.com/threads/problem-with-canvas-ui-prefabs.1039075/#post-6726169

    A multi-scene loader thingy:

    https://pastebin.com/Vecczt5Q

    My typical Scene Loader:

    https://gist.github.com/kurtdekker/862da3bc22ee13aff61a7606ece6fdd3

    Other notes on additive scene loading:

    https://forum.unity.com/threads/removing-duplicates-on-load-scene.956568/#post-6233406

    Timing of scene loading:

    https://forum.unity.com/threads/fun...ject-in-the-second-scene.993141/#post-6449718

    Also, if something exists only in one scene, DO NOT MAKE A PREFAB out of it. It's a waste of time and needlessly splits your work between two files, the prefab and the scene, leading to many possible errors and edge cases.

    Two similar examples of checking if everything is ready to go:

    https://forum.unity.com/threads/daily-events-and-content-changes.1108202/#post-7143713

    https://forum.unity.com/threads/uni...on-before-other-scripts.1153739/#post-7401794