Page 1 of 1
Set Sequence Command LoadLevel to always load the next scene in the build settings
Posted: Fri Feb 10, 2023 12:45 am
by ehdusjenny
Hello! I was wondering if it's possible to call LoadLevel or another similar Sequence command to load the next scene listed out in the build settings, without having to specify the scene/level name.
The reason I want to do this is to use the same conversation for all scene transitions since I'll have many scenes. This way I won't have to create a conversation for each scene transition where the scene/level name has to be specified in the command.
Thank you for your help!
Re: Set Sequence Command LoadLevel to always load the next scene in the build settings
Posted: Fri Feb 10, 2023 9:11 am
by Tony Li
Hi,
If you want to use the existing LoadLevel() sequencer command, you can use a Dialogue System variable. In LoadLevel(), you can specify a build index instead of a scene name by putting "index:" in front of the build index, such as:
LoadLevel(index:2)
Let's say you have a variable named sceneIndex. You could set up a dialogue entry like this:
- Dialogue Text: "Take me to the next scene."
- Script: Variable["sceneIndex"] = Variable["sceneIndex"] + 1
- Sequence: LoadLevel(index:[var=sceneIndex])
Re: Set Sequence Command LoadLevel to always load the next scene in the build settings
Posted: Thu Apr 27, 2023 10:03 pm
by ehdusjenny
Hi Tony, I apologize for the late response, I took a break from coding. Thanks for your help.
I tried running
but it printed an error saying "Scene 'index:1' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.".
So I tried running
but getting the same error.
I attached a picture of my build settings. It has two scenes so I expected "LoadLevel(index:1)" to work but not sure why it's erroring. Would you know why?
Thanks again for your help.
Re: Set Sequence Command LoadLevel to always load the next scene in the build settings
Posted: Thu Apr 27, 2023 10:29 pm
by Tony Li
Hi,
To use the "index:#" format with LoadLevel, make sure you've set up the
save system. Otherwise it will use Unity's plain old SceneManager.LoadScene("name") which doesn't understand "index:#".
Re: Set Sequence Command LoadLevel to always load the next scene in the build settings
Posted: Tue Jun 20, 2023 9:11 pm
by ehdusjenny
Yes, that fixed it! Thank you for your help once again.
Re: Set Sequence Command LoadLevel to always load the next scene in the build settings
Posted: Tue Jun 20, 2023 9:23 pm
by Tony Li
Glad to help!