How Do i Get Rid Of A Scene Without Deleting It's Objects

so basically in my scenario i have an enemy encounter similar to pokemon but when i load the next scene after the said encounter i dont want it to destroy and reset the previous scene and i am completely unsure of how to do this so can the professionals please show me how to do this one i am fairly new to unity but im willing to learn thanks :3

Prefabs should not be used to save the current state of a gameobject and load it to the next scene.
For example, if you load a prefab of an injured enemy this would be reverted to full state in the next scene.

Also there’s no way in the scene to save all the gameobject and bring them in the next scene.

BUT, you can you can add DontDestroyOnLoad to each Game Object you want to save to keep it in the next scene.


From Unity Manual DontDestroyOnLoad.

The load of a new Scene destroys all current Scene objects. Call Object.DontDestroyOnLoad to preserve an Object during level loading. If the target Object is a component or GameObject, Unity will also preserve all of the Transform’s children. Object.DontDestroyOnLoad does not return a value.
Change the argument type using the typeof operator.


You can also use Tags to define a group of gameobjects to be saved if you want to save a group of them.

The code would look like this:

public class DontDestroy : MonoBehaviour
{
    void Awake()
    {
        GameObject[] objs = GameObject.FindGameObjectsWithTag("YourTag");

        if (objs.Length > 1)
        {
            Destroy(this.gameObject);
        }

        DontDestroyOnLoad(this.gameObject);
    }
}