Forum rules - please read before posting.

How to load scene from script?

For testing purposes I've made a Unity UI dropdown menu that is automatically populated with all scenes in the project. I can load any scene from this menu by using:

UnityEngine.SceneManagement.SceneManager.LoadScene(dropdown.value, LoadSceneMode.Single);

but this causes some bugs, and I believe AC does some other stuff under the hood when loading a scene. Is there a way to load a scene from a script when you know the scenes' number?

Comments

  • Yes, you need to use AC's own ChangeScene function in order to properly handle the saving/loading of data during switching:

    AC.SceneInfo nextSceneInfo = new AC.SceneInfo (dropdown.value);
    AC.KickStarter.sceneChanger.ChangeScene (nextSceneInfo, true);
    

    Replace "true" with "false" to avoid saving the current scene's data.

  • Thanks, works perfectly! Recommend doing something like this if you have a project with many scenes and you want to playtest them on a device :)

  • To be clear, though: this should only be necessary if you're starting from an AC scene. If your opening scene isn't an AC one, then you should be able to switch scene using Unity's provided functions.

  • Good to know. I had to implement an extra menu removal function, so it might be easier to just make a standard Unity scene for device testing purposes.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.