Random MissingReferenceException after resetting database\stopping all conversations upon game restart

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
LostTrainDude
Posts: 74
Joined: Wed Mar 21, 2018 2:14 pm

Random MissingReferenceException after resetting database\stopping all conversations upon game restart

Post by LostTrainDude »

[Unity 2019.4.39f1 - AdventureCreator v1.75.3 - DS v2.2.27]

Hi Tony!

I've been experiencing a random (as in, doesn't happen every time) game-breaking issue when I restart the game. This happens mostly when I restart the game from the "end of the game", rather than from the pause menu.

Now, the game begins with a few-seconds-long cutscene and then a Conversation and this is the MissingReferenceException error I'm getting, sometimes, when that conversation starts:

Code: Select all

MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
PixelCrushers.DialogueSystem.SequencerTools.FindSpecifier (System.String specifier, System.Boolean onlyActiveInScene) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/SequencerTools.cs:165)
PixelCrushers.DialogueSystem.SequencerTools.GetSubject (System.String specifier, UnityEngine.Transform speaker, UnityEngine.Transform listener, UnityEngine.Transform defaultSubject) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/SequencerTools.cs:113)
PixelCrushers.DialogueSystem.Sequencer.HandleSetActiveInternally (System.String commandName, System.String[] args) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:1948)
PixelCrushers.DialogueSystem.Sequencer.HandleCommandInternally (System.String commandName, System.String[] args, System.Single& duration) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:1168)
PixelCrushers.DialogueSystem.Sequencer.ActivateCommand (System.String commandName, System.String endMessage, UnityEngine.Transform speaker, UnityEngine.Transform listener, System.String[] args) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:811)
PixelCrushers.DialogueSystem.Sequencer.PlayCommand (PixelCrushers.DialogueSystem.SequencerCommands.QueuedSequencerCommand commandRecord, System.String commandName, System.Boolean required, System.Single time, System.String message, System.String endMessage, System.String[] args) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:772)
PixelCrushers.DialogueSystem.Sequencer.PlayCommand (PixelCrushers.DialogueSystem.SequencerCommands.QueuedSequencerCommand commandRecord) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:741)
PixelCrushers.DialogueSystem.Sequencer.PlaySequence (System.String sequence) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:675)
PixelCrushers.DialogueSystem.Sequencer.PlaySequence (System.String sequence, System.Boolean informParticipants, System.Boolean destroyWhenDone) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:685)
PixelCrushers.DialogueSystem.ConversationView.StartSubtitle (PixelCrushers.DialogueSystem.Subtitle subtitle, System.Boolean isPCResponseMenuNext, System.Boolean isPCAutoResponseNext) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:191)
PixelCrushers.DialogueSystem.ConversationController.GotoState (PixelCrushers.DialogueSystem.ConversationState state) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:212)
PixelCrushers.DialogueSystem.ConversationController.Initialize (PixelCrushers.DialogueSystem.ConversationModel model, PixelCrushers.DialogueSystem.ConversationView view, System.Boolean alwaysForceResponseMenu, PixelCrushers.DialogueSystem.ConversationController+EndConversationDelegate endConversationHandler) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:155)
PixelCrushers.DialogueSystem.DialogueSystemController.StartConversation (System.String title, UnityEngine.Transform actor, UnityEngine.Transform conversant, System.Int32 initialDialogueEntryID) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Manager/DialogueSystemController.cs:950)
PixelCrushers.DialogueSystem.DialogueSystemController.StartConversation (System.String title, UnityEngine.Transform actor, UnityEngine.Transform conversant) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Manager/DialogueSystemController.cs:997)
PixelCrushers.DialogueSystem.DialogueManager.StartConversation (System.String title, UnityEngine.Transform actor, UnityEngine.Transform conversant) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Manager/DialogueManager.cs:475)
AC.ActionDialogueSystemConversation.Run () (at Assets/AdventureCreator/Scripts/Actions/ActionDialogueSystemConversation.cs:96)
AC.ActionList+<RunAction>d__41.MoveNext () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:425)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <ca42919df2b74e53b11002749c8755af>:0)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:375)
AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:567)
AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:526)
AC.<RunAction>d__41:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:490)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:375)
AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:567)
AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:526)
AC.<RunAction>d__41:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:490)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:375)
AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:567)
AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:526)
AC.<RunAction>d__41:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:490)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:375)
AC.ActionList:BeginActionList(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:342)
AC.ActionList:Interact(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:243)
AC.ActionRunActionList:Run() (at Assets/AdventureCreator/Scripts/Actions/ActionRunActionList.cs:169)
AC.<RunAction>d__41:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:425)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:375)
AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:557)
AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:526)
AC.<RunAction>d__41:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:490)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
When I click on the issue in the console, the GameObject pointed out is an AC Cutscene that, among other things, registers an Actor and Conversant

Image

Now, I'm not sure whether it is actually referring to these two Transforms, but, needless to say, they're in the scene.

Now, on to provide as much context as possible!

I restart the game, either through the pause menu or at the "end of the game", using custom code (that is, not by using AdventureCreator's "Engine: End Game -> Restart Game" Action) based on what I've found here, on the AdventureCreator forums.

I basically "add" to the code provided there to cater for my own needs, that includes NOT resetting the Player, as it has Addressables-loaded Here's the full method I'm using:

Code: Select all

DialogueManager.StopAllConversations();
DialogueManager.ResetDatabase();

// Stops my own sound implementation
GameSFXManager.instance.Stop();
AC.KickStarter.music.StopAll(0f);

// Clears a list of strings that stores the IDs of quests and objectives
QuestLogTracker.instance.Clear();

// Marks all the spots on the game map as "unvisited"
Navigator.instance.m_Map.Nodes.ForEach(x => x.WasVisited = false);

// Resets the status of all the "tutorial" variables
InfoPointsTracker.instance.InfoPoints.ForEach(x => x.WasChecked = false);

AC.KickStarter.runtimeInventory.SetNull();
AC.KickStarter.runtimeInventory.RemoveRecipes();

if (AC.KickStarter.settingsManager.blackOutWhenInitialising)
{
	AC.KickStarter.mainCamera.ForceOverlayForFrames(6);
}

// Resets the "quest tracking system"
ObjectiveTracker.instance.ResetIt();

AC.KickStarter.saveSystem.ClearAllData();
AC.KickStarter.levelStorage.ClearAllLevelData();

AC.KickStarter.stateHandler.Initialise(false);
AC.PlayerMenus.GetMenuWithName("Pause").TurnOff();
AC.PlayerMenus.GetMenuWithName("TopBar").TurnOff();

AC.KickStarter.eventManager.Call_OnRestartGame();

AC.KickStarter.stateHandler.CanGlobalOnStart();

AC.KickStarter.sceneChanger.ChangeScene("StartScene", false, true);

// Resets the main character outfit to the default one
OutfitManager om = AC.KickStarter.player.GetComponent<OutfitManager>();
om.WearOutfit(om.GetOutfit("default"));

// Sets an internal state machine
GameStateManager.instance.SetState(GameStates.START);
I commented the lines that are my own, so that you could have a little more context, but, to try providing even more: our game is designed using Articy Draft and we don't use Dialogue System's Quest System.

I'm straight-away observing the Lua variables imported from Articy and, when I reach a certain value while playing, I trigger either a new quest or a new objective or whatever special event needs to happen when a certain moment in the game is reached (e.g. tracking when a "tutorial popup" should appear).

That said, what I try to do while resetting (or loading) is to try and make sure I'm not re-observing the same variables and that I clear everything that needs to be cleared so to actually "reset" everything to its default state.

I'm not sure this is all necessary context, but I hope it is helpful.

In the meantime - and as always - thanks a lot!
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Random MissingReferenceException after resetting database\stopping all conversations upon game restart

Post by Tony Li »

Hi,

Are you using SequencerShortcuts component(s)?

If so, try deactivating the SequencerShortcuts when resetting the game. In addition, this patch (which will also be in version 2.2.28) should prevent the error:

DS_SequencerToolsPatch_2022-06-05.unitypackage

The error can occur if a GameObject is added as a Referenced Subject but is then deleted.

(Back up your project before importing.)
LostTrainDude
Posts: 74
Joined: Wed Mar 21, 2018 2:14 pm

Re: Random MissingReferenceException after resetting database\stopping all conversations upon game restart

Post by LostTrainDude »

Hi Tony!

The patch makes it work! I noticed that the code now null-checks the transform, should I still do something with my SequencerShortcuts components?

I do have them, just not in that first scene. I do have one in the scene that precedes the "end of the game" one, but then the "end of the game" happens in a separate scene. Do they "carry over" when I leave from a previous scene? How should I deactivate them?

Not sure if related, but I do make extensive use of custom registered Shortcuts via custom code for each actor in the game, but before loading or upon scene change (to be more specific, in the OnDisable() method) I always unregister those. In those I don't use Referenced Subjects.

Still thanks a lot for this quick patch :)
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Random MissingReferenceException after resetting database\stopping all conversations upon game restart

Post by Tony Li »

The root issue is that some GameObject isn't being unregistered for whatever reason. But, with the patch, the Dialogue System should handle it just fine if GameObjects don't get unregistered.
Post Reply