[HOWTO] How To: Manage Player Controls and Scene Changes

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Manage Player Controls and Scene Changes

Post by Tony Li »

By default, the Dialogue Manager GameObject survives scene changes. (Its Other Settings > Don't Destroy On Load and Allow Only One Instance checkboxes are ticked.) This behavior is called a "persistent singleton".

Don't assign references between persistent singletons and regular, non-persistent GameObjects in scenes. In the screenshot below, the Dialogue Manager is a persistent singleton, and the Player GameObject is a regular GameObject:

dialogueManagerDontDestroy1.png
dialogueManagerDontDestroy1.png (57.4 KiB) Viewed 1878 times
(Don't do this.)


Dialogue System messages such as "OnConversationStart" and "OnConversationEnd" are sent to the Dialogue Manager GameObject and the conversation's primary actor and conversant. (See this table.)

Let's say you've also configured another scene:

dialogueManagerDontDestroy2.png
dialogueManagerDontDestroy2.png (57.34 KiB) Viewed 1878 times
(Don't do this.)


Those scenes will play fine individually in the Unity editor's play mode. However, the Dialogue Manager from Scene 1 (or whatever scene you start in) will survive scene changes. When you change scenes, the surviving Dialogue Manager's Dialogue System Events component won't be pointing to the correct Player:

dialogueManagerDontDestroy3.png
dialogueManagerDontDestroy3.png (68.41 KiB) Viewed 1878 times

One common solution is to move the Dialogue Manager Events to the Player GameObject:

dialogueManagerDontDestroy4.png
dialogueManagerDontDestroy4.png (96.47 KiB) Viewed 1878 times

This assumes the Player is configured as the conversation's Actor:

dialogueManagerDontDestroy5.png
dialogueManagerDontDestroy5.png (27.23 KiB) Viewed 1878 times

and that the Dialogue System Trigger's Conversation Actor field is blank:

dialogueManagerDontDestroy6.png
dialogueManagerDontDestroy6.png (47.29 KiB) Viewed 1878 times

(See Character GameObject Assignments for details on how GameObjects are associated with actors in your dialogue database.)

Side note: Be careful when assigning references to prefab assets, too. If the Dialogue Manager and the prefab are all part of the same hierarchy that gets instantiated at the same time, Unity will update the reference to point to the scene instance. Otherwise, the reference will still point to the prefab version that's in the Project view, not the instance in the scene. For example, if you've pointed the Dialogue Manager's OnConversationStart() event to a player prefab, it will try to run SimpleController.enabled = false on the prefab, not the actual instance in the scene.
duolazhang
Posts: 10
Joined: Fri Oct 06, 2023 10:54 am

Re: [HOWTO] How To: Manage Player Controls and Scene Changes

Post by duolazhang »

It helps! Thank you!
shyboy0113
Posts: 4
Joined: Sat Aug 26, 2023 4:45 am

Re: [HOWTO] How To: Manage Player Controls and Scene Changes

Post by shyboy0113 »

In other words, is it correct to tell the Player to manage the status independently by assigning an Actor and Events to the Player itself, without having to touch the Player's events in Dialog Manager every Scene?

The picture below is what I understand.
Attachments
Understand.png
Understand.png (107.86 KiB) Viewed 855 times
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: [HOWTO] How To: Manage Player Controls and Scene Changes

Post by Tony Li »

Yes, exactly. Your images demonstrate it well. You can also see an example in the Interaction Tutorial at 07:00:


Post Reply