Set Sequence Command LoadLevel to always load the next scene in the build settings

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
ehdusjenny
Posts: 11
Joined: Thu Dec 29, 2022 3:58 pm

Set Sequence Command LoadLevel to always load the next scene in the build settings

Post 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!
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Sequence Command LoadLevel to always load the next scene in the build settings

Post 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])
ehdusjenny
Posts: 11
Joined: Thu Dec 29, 2022 3:58 pm

Re: Set Sequence Command LoadLevel to always load the next scene in the build settings

Post by ehdusjenny »

Hi Tony, I apologize for the late response, I took a break from coding. Thanks for your help.

I tried running

Code: Select all

LoadLevel(index:[var=sceneIndex])
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

Code: Select all

LoadLevel(index:1)
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.
Attachments
Capture.PNG
Capture.PNG (8.07 KiB) Viewed 1007 times
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Sequence Command LoadLevel to always load the next scene in the build settings

Post 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:#".
ehdusjenny
Posts: 11
Joined: Thu Dec 29, 2022 3:58 pm

Re: Set Sequence Command LoadLevel to always load the next scene in the build settings

Post by ehdusjenny »

Yes, that fixed it! Thank you for your help once again.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Sequence Command LoadLevel to always load the next scene in the build settings

Post by Tony Li »

Glad to help!
Post Reply