Page 1 of 1

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

Posted: Sat Jun 18, 2022 8:38 am
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 1882 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 1882 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 1882 times

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

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

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

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

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

dialogueManagerDontDestroy6.png
dialogueManagerDontDestroy6.png (47.29 KiB) Viewed 1882 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.

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

Posted: Fri Oct 20, 2023 2:00 pm
by duolazhang
It helps! Thank you!

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

Posted: Mon Oct 30, 2023 2:29 am
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.

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

Posted: Mon Oct 30, 2023 7:10 am
by Tony Li
Yes, exactly. Your images demonstrate it well. You can also see an example in the Interaction Tutorial at 07:00: