- Home /
GetSceneByPath fails after LoadScene (Async or not) - Unity 5.5.2
Hi,
I've updated my unity to 5.5.2, and since them I'm having the most peculiar problem:
SceneManager.GetSceneByPath()
returns an uninitialized Scene
object, even if the scene was loaded. This happens only if you use scenes which are not in the main Assets dir.
The following code to demonstrates the problem:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneTesting : MonoBehaviour {
Scene m_scene;
string m_sceneName;
AsyncOperation m_loadingStatus;
bool loadSync = false;
bool loadAsync = true;
// Use this for initialization
void Start () {
m_sceneName = "Scenes/Levels/Small/Scene2";
m_loadingStatus = null;
if (loadAsync)
m_loadingStatus = SceneManager.LoadSceneAsync(m_sceneName, LoadSceneMode.Additive);
}
void ProcessSceneAsync()
{
// Using just "Scene2" here will work
m_scene = SceneManager.GetSceneByPath(m_sceneName);
Debug.Log("Scene " + (m_scene.isLoaded ? "Loaded" : "Not Loaded"));
}
void ProcessSceneSync()
{
SceneManager.LoadScene(m_sceneName, LoadSceneMode.Additive);
m_scene = SceneManager.GetSceneByPath(m_sceneName);
Debug.Log("Scene " + (m_scene.isLoaded ? "Loaded" : "Not Loaded"));
}
// Update is called once per frame
void Update () {
if (m_loadingStatus != null && m_loadingStatus.isDone)
{
m_loadingStatus = null;
ProcessSceneAsync();
}
if (loadSync)
ProcessSceneSync();
loadSync = false;
}
}
As you see, this project has 2 scenes. One is the main (preloaded) scene, and the other is in Scenes/Levels/Small/Scene2.unity. This code demonstrates loading Scene2 using LoadScene()
and LoadSceneAsync()
. After the loading is finished, it calls GetSceneByPath()
and logs the output.
For this code, I'm always getting "Scene Not Loaded" in the log - GetSceneByPath()
fails. If I change m_sceneName
to just "Scene2" - GetSceneByPath()
succeeds.
Am I doing something wrong here? Is this indeed a bug? (I've reported it as a bug and haven't heard from Unity yet)
Thanks, Nitay
Your answer
