- Home /
InvalidOperationException: This can only be used during play mode, please use EditorSceneManager.OpenScene() instead.
Hi everybody. I was experiencing this error on 2017 and I updated to 2018 to find it persists.
InvalidOperationException: This can only be used during play mode, please use EditorSceneManager.OpenScene() instead.
When I double click on the console log it takes me to the following line of code: Application.LoadLevel(sceneIndex); I am well aware that it is deprecated but using Scenemanager.LoadScene gives me exactly the same error.
Below the class it's getting the error.
public class Scener : MonoBehaviour {
public static Scener _instance;
public static Scener Instance
{
get
{
if (_instance == null)
{
_instance = new GameObject("scener").AddComponent<Scener>();
}
return _instance;
}
}
public void LoadScene(int sceneIndex)
{
Application.LoadLevel(sceneIndex);
}
}
Any help would be greatly appreciated!
Answer by ak98 · Jun 12, 2018 at 07:20 PM
Try SceneManager.LoadScene("OtherSceneName"); But for this to be used in your script you need to add using UnityEngine.SceneManagement; At the top of the script under the other "using" stuff. so that you can use the scene manager.
Answer by Pablomon · Jun 23, 2018 at 05:50 PM
Either SceneManager.LoadScene(sceneIndex) or Application.LoadLevel(sceneIndex) throw at me the same error :
InvalidOperationException: This can only be used during play mode, please use EditorSceneManager.OpenScene() instead.
I am really lost here and can't build my project.. Can anybody throw some light on this??
Thank you