Page 1 of 2

3D Quest objective marker?

Posted: Sun Aug 01, 2021 10:46 am
by Strook
Hello, I'm planning to add a feature to our game, which is a Quest objective marker: https://assetstore.unity.com/packages/t ... ors-153472

When you track a quest from your quest log, I want to display a 2d on screen marker, pointing to a specific location

What do you think would be the best way to do approach this system, knowing all my quest are using Dialogue System Quests.
Ideally I would like to have a location for each Quest entry, but Im not sure how and where to store this data (a gameobject from the scene? a "location" ?)

Thanks!

Re: 3D Quest objective marker?

Posted: Sun Aug 01, 2021 11:42 am
by Tony Li
Hi,

You could add a script to the GameObject that has dropdowns for the quest and quest entry. Use [QuestPopup] and [QuestEntryPopup] attributes:

Code: Select all

public class QuestMarker : MonoBehaviour
{
    [QuestPopup] public string questName;
    [QuestEntryPopup] public int questEntry;
    
    private void Start()
    {
        UpdateMarker();
    }
    
    public void UpdateMarker()
    {
        if (QuestLog.IsQuestActive(questName) && QuestLog.GetQuestEntryState(questName, questEntry) == Quest.Active)
        {
            // Show marker
        }
        else
        {
            // Hide marker
        }
    }
}
In practical terms, you'll probably want to automatically update markers when quest entry states change. Ideally you'd register your markers with a manager script. But a quick-and-dirty first version could be:

Code: Select all

public class QuestMarkerManager : MonoBehaviour
{
    private void Awake()
    {
        QuestLog.SetQuestEntryStateOverride = SetQuestEntryStateAndUpdateMarkers;
    }
    
    private void SetQuestEntryStateAndUpdateMarkers(string questName, int entryID, string state)
    { // (Would be better for each QuestMarker to register itself in a list instead of FindObjectsOfType.)
        foreach (QuestMarker questMarker in FindObjectsOfType<QuestMarker>())
        {
            questMarker.UpdateMarker();
        }
    }
}

Re: 3D Quest objective marker?

Posted: Sun Aug 01, 2021 11:56 am
by Strook
thanks for this solution, this seems very elegant!

Re: 3D Quest objective marker?

Posted: Sun Aug 01, 2021 12:03 pm
by Tony Li
Glad to help! Please let me know how it goes. I've added that asset to my list of things to look at. I might add official integration at some point.

Re: 3D Quest objective marker?

Posted: Fri Oct 27, 2023 9:45 am
by Fitbie
I have question about quest manager - is it some event in Dialogue System telling listeners that any quest change its state?
Like watcher pattern with quests state

Re: 3D Quest objective marker?

Posted: Fri Oct 27, 2023 10:01 am
by Tony Li
Hi,

Yes. The "OnQuestStateChange" message is sent to the Dialogue Manager GameObject's hierarchy.

You can add a script with an OnQuestStateChange(string questName) method to the Dialogue Manager, or add a Dialogue System Events component and configure its OnQuestStateChange() UnityEvent.

Re: 3D Quest objective marker?

Posted: Sat Oct 28, 2023 11:00 am
by Fitbie
I have one more question :) I need to draw mark on map when player starts tracking some quest.
I know about OnQuestTrackingEnabled(string questTitle)
However, I don't want to write additional managers and I decided to extend your QuestStateListener by deriving
Since it is connected to QuestDispatcher and there is no OnQuestTrackingEnable there, I wanted to know how I can know when the player starts tracking the quest (to draw a mark on the map).
I tried (QuestLog.IsQuestTrackingEnabled(questName))
However, either this function just tells me if the quest can be tracked, or starting track quest does not trigger OnQuestStateChange in the dispatcher - nothing happens


I could extend Dispatcher and fix all of it, but then i need to override QuestStateDispatcher property in QuestStateListener, but its not virtual (bc i need to add my dispatcher with OnQuestTrackingEnabled, not yours)

Also i have variant manually add my custom dispatcher to dialogue manager GO, but it seems dirty.
I need tip from experienced developer :)

Re: 3D Quest objective marker?

Posted: Sat Oct 28, 2023 11:05 am
by Tony Li
Hi,

QuestLog.IsQuestTrackingAvailable(questName) tells you if the quest is allowed to be tracked -- that is, if the quest log window shows a Track toggle that the player can turn on and off.

QuestLog.IsQuestTrackingEnabled(questName) tells you if the Track toggle has been turned on.

Re: 3D Quest objective marker?

Posted: Sun Oct 29, 2023 11:16 am
by Fitbie
As far as I understand OnQuestStateChange() is not called when we start / stop tracking a quest. This is the responsibility of OnQuestTrackingEnabled() method
The only solution I can see is to modify the QuestStateDispatcher component and add the OnQuestTrackingEnabled/Disabled() method there, and also make the m_listeners field protected for deriving, instead of private so that I can send a message to the listeners (i need to know what listeners is). I know that changing your code is bad, but unfortunately with inheritance I can't get the m_listeners field

Or make another dispatcher for listening for OnQuestTrackingEnabled()

Re: 3D Quest objective marker?

Posted: Sun Oct 29, 2023 12:30 pm
by Tony Li
Hi,

This version of QuestStateDispatcher.cs will be in DS version 2.2.41. There is a public listeners property, and all methods are virtual.

DS_QuestStateDispatcherPatch_2023-10-29.unitypackage