QuestItemUI is destroyed (Infinite reward glitch) [FIXED: Check last comment]

Alright so we spoke of this bug before, but apparently it doesn’t seem to be properly resolved. When I play the game to a high level, and I try starting the quest I have in my game, the first red flag that leads to the infinity reward glitch begins after trying to close the end of the Quest-giving conversation (i.e: ‘GiveQuest’ is triggered), and this is the stack trace that it leads to (P.S: it usually doesn’t happen if we are just starting the game, at a low level):

MissingReferenceException: The object of type 'QuestItemUI' 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.
UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Transform parent, System.Boolean instantiateInWorldSpace) (at <ba783288ca164d3099898a8819fcec1c>:0)
UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Transform parent, System.Boolean worldPositionStays) (at <ba783288ca164d3099898a8819fcec1c>:0)
UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Transform parent) (at <ba783288ca164d3099898a8819fcec1c>:0)
QuestListUI.Redraw () (at Assets/Project Backup/Scripts/UI/Quests/QuestListUI.cs:37)
RPG.Quests.QuestList.CompleteObjective (RPG.Quests.Quest quest, System.String objective) (at Assets/Project Backup/Scripts/Quests/QuestList.cs:61)
RPG.Quests.QuestCompletion.CompleteObjective () (at Assets/Project Backup/Scripts/Quests/QuestCompletion.cs:16)
UnityEngine.Events.InvokableCall.Invoke () (at <ba783288ca164d3099898a8819fcec1c>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <ba783288ca164d3099898a8819fcec1c>:0)
RPG.Dialogue.DialogueTrigger.Trigger (System.String actionToTrigger) (at Assets/Project Backup/Scripts/Dialogue/DialogueTrigger.cs:19)
RPG.Dialogue.PlayerConversant.TriggerAction (System.String action) (at Assets/Project Backup/Scripts/Dialogue/PlayerConversant.cs:180)
RPG.Dialogue.PlayerConversant.TriggerExitAction () (at Assets/Project Backup/Scripts/Dialogue/PlayerConversant.cs:168)
RPG.Dialogue.PlayerConversant.Quit () (at Assets/Project Backup/Scripts/Dialogue/PlayerConversant.cs:46)
RPG.UI.DialogueUI.<Start>b__8_1 () (at Assets/Project Backup/Scripts/UI/DialogueUI.cs:30)
UnityEngine.Events.InvokableCall.Invoke () (at <ba783288ca164d3099898a8819fcec1c>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <ba783288ca164d3099898a8819fcec1c>:0)
UnityEngine.UI.Button.Press () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:514)

Any idea how to resolve this issue? After finishing the quest, if I try closing the reward dialogue at the end, I get the same reward everytime I hit ‘X’, and if I try walk away, the reward gets tripled… The only way out is to re-talk to the quest giver, and then walk away (which is a very obvious bug I don’t want in my game)

This is the QuestListUI.Redraw method…

    private void Redraw()
        foreach (Transform item in transform)
        foreach (QuestStatus status in questList.GetStatuses())
            QuestItemUI uiInstance = Instantiate<QuestItemUI>(questPrefab, transform);

There are two things that can be QuestItem UI here, either the questPrefab, or the uiInstance…
Since the uiInstance was just created, it seems unlikely that it would be the thing that would return a Missing Reference Excepction (even a null reference would be unlikely here, because the Instantiate would have failed…

This leaves the only thing that can be null the questPrefab…

Make sure that in your QuestListUI component within Unity that your questPrefab is linked to a prefab in the assets folder and NOT a sample QuestItemUI within the content of the QuestListUI container…

yup, that was the case… it still acts up from time to time (but at this point in time I’m convinced it’s a performance issue than a game coding issue)

Update for anyone who gets stuck in this bug later down the line:

Open up ‘QuestList.cs’ and comment out the ‘onUpdate()’ action call in both ‘AddQuest()’ and ‘CompleteObjective()’

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

If this was the fix… then something subscribed to QuestList.onUpdate() and failed to unsubscribe when it was destroyed…

Privacy & Terms