I have a Game Object that marked as “do not delete” so it will stick around when a new Scene is loaded. This seems to be an old Unity concept maybe? With newer Scene Manager code, you can load a new Scene async and then tell the original Scene to become inactive when the new one is loaded. Is there a way to make a persistent object come over to the new Scene instead of just stopping running when it’s in the inactive Scene?
I’m not sure about “old Unity concept”; I think it’s still a valid option.
However, there is: Unity - Scripting API: SceneManagement.SceneManager.MoveGameObjectToScene
If that’s what you want.
I’m already using that. But it doesn’t appear to continue running scripts on a game object that’s in the “inactive” scene once it becomes inactive. Is that normal? I thought that it might be.
Thanks, would there be an event I could use there to wire that up that tells me when the Scene is done loading async?
There are built-in events for scene loaded, unloaded, and active scene changed. I think beyond that, you’d have to create your own.
Just out of curiosity, does your object get destroyed when you load a new scene and unload the old one or just stop running your scripts? I haven’t a lot of experience with that, so just wondering. ![]()
Maybe I’d check that out some time to see.
that is not normal scripts on objects that use DontDestroyOnLoad(this.gameObject); should continue to run after the new scene is loaded and the old one removed i made a simple test i can share if u like
using UnityEngine;
using UnityEngine.SceneManagement;
public class Save : MonoBehaviour
{
private static bool created = false;
void Awake()
{
if (!created)
{
DontDestroyOnLoad(this.gameObject);
created = true;
Debug.Log("Awake: " + this.gameObject);
}
}
[ContextMenu("LoadScene")]
public void LoadScene()
{
SceneManager.LoadSceneAsync(1, LoadSceneMode.Single);
}
public void FixedUpdate()
{
Debug.Log("Update");
}
}