RestoreOriginalUI() thows MissingReference Error
Posted: Tue Feb 15, 2022 5:58 pm
Hello,
I've identified a pretty edge case bug in my game that unfortunately breaks everything, and after a couple attempts I'm not exactly sure how to diagnose it. I apologize in advance that this is a long post, but I wanted to be able to provide as much specific information as I can to the situation, in case anything catches your eye as being the potential issue.
The bug is as follows:
A the end of certain conversations, when RestoreOriginalUI() is called in the DialogueSystemController, and line 1228 throws a MissingReferenceException error. Here's line 1228 of my version of the Dialogue UI.
As far as I can tell the issue has to do with there not being a dialogueUI to reset to as the default one.
Here is some additional context, as I have narrowed down the instances where this happens.
In my game there are loops, and the same scene is reloaded to show a loop, naturally the Dialogue System is one of the few objects that is not destroyed. I have it set up to select a default Dialogue UI when the scene reloads each time.
The bug is only happening after the scene has reloaded once.
The bug is also only happening after initiating certain conversations in a particular order.
One type of conversation is a phone call - which has a specific Dialogue UI. Phone calls are started via script by calling DialogueManger.StartConversation(). I manually set the dialogue ui through script using DialogueManager.UseDialogueUI(). There is also a player Actor that has DialogueSettingsOverride that also points to the correct DialogueUI. Writing this out now that seems potentially redundant. If I initiate a phone call at the start of a loop everything is fine throughout the rest of the loop and the bug doesn't occur.
Another type of conversation is with in-world objects. These are started through triggering a DialogueSystemTrigger, and have a different DialogueUI than phone calls. There is an Actor used for these environmental dialogues that has a Dialgoue Setting Override attached to it, so that when the player initiates an in-world conversation it opens the right DialogueUI.
This is the specific condition that the bug occurs: After the first loop, so once the scene has reloaded once, if you initiate a conversation with an in-world object, when that conversation is done Unity throws the MissingReferenceException error. From then on out if you try to start any new conversations it will throw the same error and the conversation is never started.
However, if you happen to start a phone call conversation first, the error never occurs, and you can go on to have as many of either types of conversations as you like. In the next loop, the same holds true, as long as you start by having a phone conversation nothing bugs, and you're good for the rest of the loop, but if you start any loop other than the first one by having a conversation with an in-world object then the error is thrown.
I'm thinking it must be something about how I'm setting the DialogueUI of the main DialogueSystemController between loops, or perhaps the difference between setting the dialogue UI manually through script versus through an Override.
Again, I'm sorry that this is a long post. I really appreciate any insight you can shed on the situation. I'm also happy to provide any additional details you think might be relevant about my specific set up. Though I'm grateful I've dialed in on exactly when this is happening, none of my tweaks to my set up have resulted in any success.
Thanks in advance and no worries if nothing comes to mind, I understand this might be specific to my setup/not easily solved via a forum post.
I've identified a pretty edge case bug in my game that unfortunately breaks everything, and after a couple attempts I'm not exactly sure how to diagnose it. I apologize in advance that this is a long post, but I wanted to be able to provide as much specific information as I can to the situation, in case anything catches your eye as being the potential issue.
The bug is as follows:
A the end of certain conversations, when RestoreOriginalUI() is called in the DialogueSystemController, and line 1228 throws a MissingReferenceException error. Here's line 1228 of my version of the Dialogue UI.
Code: Select all
displaySettings.dialogueUI = (m_originalDialogueUI as MonoBehaviour).gameObject;
Here is some additional context, as I have narrowed down the instances where this happens.
In my game there are loops, and the same scene is reloaded to show a loop, naturally the Dialogue System is one of the few objects that is not destroyed. I have it set up to select a default Dialogue UI when the scene reloads each time.
The bug is only happening after the scene has reloaded once.
The bug is also only happening after initiating certain conversations in a particular order.
One type of conversation is a phone call - which has a specific Dialogue UI. Phone calls are started via script by calling DialogueManger.StartConversation(). I manually set the dialogue ui through script using DialogueManager.UseDialogueUI(). There is also a player Actor that has DialogueSettingsOverride that also points to the correct DialogueUI. Writing this out now that seems potentially redundant. If I initiate a phone call at the start of a loop everything is fine throughout the rest of the loop and the bug doesn't occur.
Another type of conversation is with in-world objects. These are started through triggering a DialogueSystemTrigger, and have a different DialogueUI than phone calls. There is an Actor used for these environmental dialogues that has a Dialgoue Setting Override attached to it, so that when the player initiates an in-world conversation it opens the right DialogueUI.
This is the specific condition that the bug occurs: After the first loop, so once the scene has reloaded once, if you initiate a conversation with an in-world object, when that conversation is done Unity throws the MissingReferenceException error. From then on out if you try to start any new conversations it will throw the same error and the conversation is never started.
However, if you happen to start a phone call conversation first, the error never occurs, and you can go on to have as many of either types of conversations as you like. In the next loop, the same holds true, as long as you start by having a phone conversation nothing bugs, and you're good for the rest of the loop, but if you start any loop other than the first one by having a conversation with an in-world object then the error is thrown.
I'm thinking it must be something about how I'm setting the DialogueUI of the main DialogueSystemController between loops, or perhaps the difference between setting the dialogue UI manually through script versus through an Override.
Again, I'm sorry that this is a long post. I really appreciate any insight you can shed on the situation. I'm also happy to provide any additional details you think might be relevant about my specific set up. Though I'm grateful I've dialed in on exactly when this is happening, none of my tweaks to my set up have resulted in any success.
Thanks in advance and no worries if nothing comes to mind, I understand this might be specific to my setup/not easily solved via a forum post.