Dialogue not loading on "unactive" scene.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
joshcunn
Posts: 3
Joined: Sat Jul 09, 2016 2:06 pm

Dialogue not loading on "unactive" scene.

Post by joshcunn »

I am creating a game where there are several dialogues across the story, but only the first dialogue loads when I start the game from the beginning. Any conversation after that doesn't load unless I stop the game and restart from that specific scene. Basically, if I'm not on that scene when I start, the dialogue won't load. Anyway to fix this? I am in a 2D game where the mouse and clicking are the only controls. Thanks!
irve
Posts: 53
Joined: Fri Jan 15, 2016 9:35 am

Re: Dialogue not loading on "unactive" scene.

Post by irve »

For me this "dialogue only once" happened when I made a broken user interface, which didn't work twice. Don't forget that you can turn on logging on Dialogue Manager component to see any errors of the "second activation".
User avatar
Tony Li
Posts: 20993
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue not loading on "unactive" scene.

Post by Tony Li »

As @irve writes, temporarily setting the Dialogue Manager's Debug Level to Info can be very helpful. Look for yellow warning lines in the Console window, or any lines that start with "Dialogue System:".

Do you have separate Dialogue Manager GameObjects in each scene? If so, do they point to different dialogue databases?

By default, the Dialogue Manager acts as a "persistent singleton." This means it survives scene changes, and like a Highlander there can be only one. The Dialogue Manager maintains its own Lua environment containing all of the runtime changes to variable values, etc. You can still have a separate Dialogue Manager in each scene to make it easy to playtest the scene, but keep in mind that if you're coming in from a previous scene, the Dialogue Manager will be the one from the previous scene.

If you have separate Dialogue Managers with different dialogue databases, here are a few solutions:

1. Use a single database. You can merge your databases using the Merge tool on the Dialogue Editor window's Database tab.

2. Or, use Extra Databases components in each scene to automatically add the extra databases into the persistent singleton Dialogue Manager. For example, if Scene2 has its own dialogue database Scene2DB, create an empty GameObject, add an Extra Databases component, and assign Scene2DB to the Databases section. Then set the Add Trigger to OnStart and the Remove Trigger to OnDestroy.

3. Or, turn off the persistent singleton configuration by inspecting each of your Dialogue Managers and unticking Don't Destroy On Load and Allow Only One Instance. The disadvantage of this solution is that you won't retain runtime changes to variable values across scene changes, since each Dialogue Manager maintains its own copy of those variables. (Technically you can save the state before leaving the previous scene, and then apply it to the new Dialogue Manager after entering the new scene. If you want info on that, let me know. It's 2 lines of code.)

If none of that helps, please feel free to post more info and/or screenshots here, or send an example project to tony (at) pixelcrushers.com. I'll be happy to take a look.
joshcunn
Posts: 3
Joined: Sat Jul 09, 2016 2:06 pm

Re: Dialogue not loading on "unactive" scene.

Post by joshcunn »

Thanks both of you so much! I went with Tony's third idea of unticking those two boxes and that worked perfectly! I believe the issue was I had multiple databases but I was so far along in the game it would've been unbearable to redo all of the conversations. Thanks again! :D
User avatar
Tony Li
Posts: 20993
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue not loading on "unactive" scene.

Post by Tony Li »

If that works for your needs, great!

If you decide in the future that you need variable values to persist across scene changes, you can merge your multiple databases into a single one without having to redo any of them. Just use the Merge tool on the Dialogue Editor window's Database tab. Or you can keep them as separate databases and load them all into memory simultaneously using the Extra Database component.
OneManOnMars
Posts: 105
Joined: Tue Apr 05, 2016 9:37 am

Re: Dialogue not loading on "unactive" scene.

Post by OneManOnMars »

Cool, this was exactly what I was looking for. Had to google exactly once! Thank you Tony Li for the perfect answer.
User avatar
Tony Li
Posts: 20993
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue not loading on "unactive" scene.

Post by Tony Li »

Happy I could help!
OneManOnMars
Posts: 105
Joined: Tue Apr 05, 2016 9:37 am

Re: Dialogue not loading on "unactive" scene.

Post by OneManOnMars »

Can I create a Dialogue Manager Prefab so if I change it in one scene it also changes in scene 1 and therefore is always up to date?
User avatar
Tony Li
Posts: 20993
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue not loading on "unactive" scene.

Post by Tony Li »

Sure. That's what most devs do.
OneManOnMars
Posts: 105
Joined: Tue Apr 05, 2016 9:37 am

Re: Dialogue not loading on "unactive" scene.

Post by OneManOnMars »

Tony Li wrote:Sure. That's what most devs do.
perfect, thanks for the quick answer.
Post Reply