- Home /
Instance on wrong scene (Unity 5.4 beta)
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?
Some code would help here... Which scene are you in? Have you loaded them additively or in single scene mode? How are you referencing the objects?
We're experiencing the same issue. Unity version: 5.3.5f1, 5.3.5p1, 5.3.5p2, 5.3.5p3, 5.3.5p4 We're loading scenes additively. Some objects (we don't have a clear repro case right now) will get instantiated in the scene we loaded as single.
Our flow is: - Load scene_a, single mode - Load scene_b, additively - Load scene_c, additively
Then we have several scripts that will, at some point, instantiate stuff. One of the scripts in scene_b (single instance, only loaded with that specific scene) will ALWAYS instantiate objects as part of scene_a.
Answer by BakewellTorte · Jan 05, 2017 at 10:26 AM
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/
Answer by Lune · May 17, 2016 at 04:47 AM
having the same issue at the moment, tried with "SetActiveScene" didnt work.
Answer by Astiolo · Jan 25, 2017 at 08:08 AM
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.