I have two scenes:
A BaseScene with a GameManager object that receives two prefabs.
A Bedroom scene, with a RoomInit script that will get the prefabs references from the GameManager and instantiate them.
However, I was expecting to have the objects instantiated on the Bedroom scene rather than the BaseScene .
Why is that? Can I set which scene I want my objects instantiated?
I was having the same problem…the solution is pretty straightforward.
Load your Scenes in a Coroutine and wait one from between each call. Apparently you can’t set a Scene as the Active Scene in the same frame that you load it because it’s not actually loaded yet.
private IEnumerator LoadLevel(int sceneIndex)
{
yield return new WaitForEndOfFrame();
UnloadAllScenes();
SceneManager.LoadScene(m_levelRootSceneIndex, LoadSceneMode.Additive);
yield return null;
SceneManager.LoadScene(sceneIndex, LoadSceneMode.Additive);
yield return null;
SceneManager.SetActiveScene(SceneManager.GetSceneAt(sceneIndex));
}
Found the solution here. Credit to @NioFox
https://forum.unity3d.com/threads/scenemanager-loadscene-additive-and-set-active.380826/
A solution I found to be easier for myself, was to set the parent of the instantiated object to something that’s already in the scene that I wanted.
Lune
May 17, 2016, 4:47am
2
having the same issue at the moment, tried with “SetActiveScene” didnt work.