- Home /
Assign SceneAsset through Inspector for LoadScene?
Hi gang,
TLDR: I'm looking to load a scene through the Inspector via the following line:
SceneManager.LoadScene(nextScene.ToString());
I'm pretty green when it comes to programming and I'm trying to make a mechanism where I load scenes in a way that empowers the designer, where they don't need to know about the code or build index order.
My approach was by using the following line of code when the player goes through a trigger:
SceneManager.LoadScene(nextScene.ToString());
I then dragged the Scene into the Inspector:
The trigger fires but I get this error:
My 2 scenes are both in the Build Settings so that's not an issue. I've removed, re-added and rearranged them just in case it was a bug but had no luck. Is this something to with an AssetBundle? I know nothing about how those work and it seems to be quite complex for what I thought was a simple ToString()
conversion of an asset's name.
Am I close? Am I delusional that a designer could user Unity's Inspector to hook all this up without custom property drawers or complicated code solutions?
Thanks for any guidance.
Answer by Tanteturner · Dec 07, 2020 at 08:30 PM
You have to do nextScene.name
because SceneManager.LoadScene(nextScene.ToString());
returns "Sandbox2 (UnityEngine.Sceneasset)"
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Check if Scene exists in Build Settings? 2 Answers
Using as AssetBundle to replace first scene 2 Answers
Multiple Cars not working 1 Answer
Scene assets not bundled in asset bundle 0 Answers