Problems with Quest Completion

Hi, I can’t get my UI to update the quest completion at all. Watched the video several times, even copied the script from git and still having the same issue. When I debug it the quest does get completed but UI never gets updated which is strange cuz it updates the new quest, I’m sure its something simple I am missing but I cant see it myself and I’ve been stuck at it for awhile. plz help

Let’s take a look at your QuestList.cs, your QuestListUI.cs, and QuestItemUI.cs scripts for a start.

Thanks for the fast reply. here it is

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace RPG.Quests
{
    public class QuestList : MonoBehaviour
    {
        List<QuestStatus> statuses = new List<QuestStatus>();

        public event Action onUpdate;

        public void AddQuest(Quest quest)
        {
            if (HasQuest(quest)) return;
            QuestStatus newStatus = new QuestStatus(quest);
            statuses.Add(newStatus);
            if (onUpdate != null)
            {
                onUpdate();
            }
        }

        public void CompleteObjective(Quest quest, string objective)
        {
            QuestStatus status = GetQuestStatus(quest);
            status.CompleteObjective(objective);
            if (onUpdate != null)
            {
                onUpdate();
            }
        }

        public bool HasQuest(Quest quest)
        {
            return GetQuestStatus(quest) != null;
        }

        public IEnumerable<QuestStatus> GetStatuses()
        {
            return statuses;
        }

        private QuestStatus GetQuestStatus(Quest quest)
        {
            foreach (QuestStatus status in statuses)
            {
                if (status.GetQuest() == quest)
                {
                    return status;
                }
            }
            return null;
        }
    }

}

using System.Collections;
using System.Collections.Generic;
using RPG.Quests;
using UnityEngine;

public class QuestListUI : MonoBehaviour
{
    [SerializeField] QuestItemUI questPrefab;
    QuestList questList;

    void Start()
    {
        questList = GameObject.FindGameObjectWithTag("Player").GetComponent<QuestList>();
        questList.onUpdate += Redraw;
        Redraw();
    }

    private void Redraw()
    {
        transform.DetachChildren();
        foreach (QuestStatus status in questList.GetStatuses())
        {
            QuestItemUI uiInstance = Instantiate<QuestItemUI>(questPrefab, transform);
            uiInstance.Setup(status);
        }
    }
}

using System.Collections;
using System.Collections.Generic;
using RPG.Quests;
using TMPro;
using UnityEngine;

public class QuestItemUI : MonoBehaviour
{
    [SerializeField] TextMeshProUGUI title;
    [SerializeField] TextMeshProUGUI progress;

    QuestStatus status;

    public void Setup(QuestStatus status)
    {
        this.status = status;
        title.text = status.GetQuest().GetTitle();
        progress.text = status.GetCompletedCount() + "/" + status.GetQuest().GetObjectiveCount();
    }

    public QuestStatus GetQuestStatus()
    {
        return status;
    }
}

Let’s add some Debugs to test setup…

Redraw happens when quest completes however UI still does not update

image

Hmm… I wonder if you’re getting them at all… Add one more Debug within the foreach loop

Debug.Log("Foreach");

If that’s not logging, we need to see why QuestList isn’t returning any Status in GetStatus(), so that will be the next code paste.

image

I’m officially baffled. Zip up your project and upload it to https://gdev.tv/projectupload (be sure to remove the Library folder) and I’ll take a look. I’m at work now, so I won’t be able to get to it until later this evening.

As it turns out the Quest UI is working perfectly. The issue was that the Quest objective wasn’t being fulfilled.

With the QuestList open when talking to the quest giver, the QuestListUI correctly showed the quest with 0/2

The character next to him with the stranger check tries to fulfill a Quest Condition named “1”, but at this point in the course, our Quests are a list of strings. Changing the condition to fulfill to “Get poppy milk” then facilitated the change from 0/2 to 1/2.

A bit later in the course, we’ll be adding an Objective class that allows us to use shorter identifiers (Like “1”) to represent the full objective, but for now, we need to use the entire objective name.

Thank you so much, that fixes the issue.

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

Privacy & Terms