- Home /
SceneManager.LoadScene() returns void, so how can I get the the scene being loaded.
SceneManager.LoadScene() returns void, so how can I get the the scene being loaded.
Answer by KloverGames · Apr 29 at 01:43 PM
SceneManager.LoadScene(0); //Loads the scene by index in the Build Settings
SceneManager.LoadScene("Scene Name"); //Loads the scene by name
SceneManager.LoadScene(SceneManager.GetActiveScene().name); //Reloads the current scene
You're probably looking for SceneManager.GetActiveScene(); which of course gets the scene you're current in.
I'd like to have an return value from SceneManager.LoadScene(); Is there any way simlimar to have an return value from SceneManager.LoadScene();?
It is a bit strange and complicated. 【1】I want to clear some cache before building the project. 【2】Before clearing, I want to change to an empty scene, because in normal scene the cache may appear again which makes clearing in vain. 【3】So I want to run SceneManager.LoadScene() in Editor script. And because scene loading is not completed immediately, I want to get the scene and check scene.isLoaded. 【4】Finally, Unity said SceneManager.LoadScene() can not be run in Editor script and suggested me to use EditorSceneManager.OpenScene(). EditorSceneManager.OpenScene() works, good ending. 【5】EditorSceneManager.OpenScene() returns the scene, but SceneManager.LoadScene() returns void. So I have a doubt and come here to ask this question.
Your answer
Follow this Question
Related Questions
Load scene with buildindex equal to a int variable. 1 Answer
How can I instantiate a player into a scene I just loaded in the same function 1 Answer
How do I preload multiple scenes at once? 0 Answers
How to unsubscribe from InputSystem event properly 1 Answer
Scene takes long to load only first time 2 Answers