SetTag not working

Announcements, support questions, and discussion for Quest Machine.
random
Posts: 34
Joined: Thu May 09, 2024 10:48 pm

SetTag not working

Post by random »

Hello!

I read this in the manual for QM.
A quest instance is an in-memory copy of a quest asset. There may be many quest instances of a quest asset.
Would this prevent SetTag from being applied properly? I'm looping through all the Quests DBs/Quests on the Quest Machine Configuration Component in Awake(). All my questDBs are divided by in game locations and I'm trying to add a tag {REGION}. But in UI is just shows "REGION".

Here is the relevant code I'm using:

Code: Select all

private void SetTagForAllQuests(QuestDatabase questDB, string tag)
{
	foreach (Quest quest in questDB.questAssets)
	{
		quest.tagDictionary.SetTag("REGION", tag);
	}
}
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: SetTag not working

Post by Tony Li »

Hi,

If it's in your script's Awake() method (I strongly recommend against directly modifying QM scripts themselves), it should be fine to set the tag. You can set "REGION" and then any text that contains "{REGION}" should show the value of the tag.
random
Posts: 34
Joined: Thu May 09, 2024 10:48 pm

Re: SetTag not working

Post by random »

Unfortunately, I'm not sure why it isn't working correctly.
Screenshot 2024-07-09 213000.png
Screenshot 2024-07-09 213000.png (14.68 KiB) Viewed 1309 times
Screenshot 2024-07-09 212951.png
Screenshot 2024-07-09 212951.png (10.05 KiB) Viewed 1309 times


Here is the entire script I'm using if it helps. It is attached to the QuestMachine prefab.

Code: Select all

using PixelCrushers.QuestMachine;
using UnityEngine;

namespace AIL.Helpers
{
	public class SetSceneNameTags : MonoBehaviour
	{
		private QuestMachineConfiguration _qmConfig;

		private static readonly string SceneNameTag = "REGION";

		private void Awake()
		{
			_qmConfig = GetComponent<QuestMachineConfiguration>();
			foreach (QuestDatabase questDB in _qmConfig.questDatabases)
			{
				if (questDB.description == "SampleScene")
				{
					SetTagForAllQuests(questDB, "Sample Scene");
				}
			}
			
		}

		private void SetTagForAllQuests(QuestDatabase questDB, string tag)
		{
			foreach (Quest quest in questDB.questAssets)
			{
				quest.tagDictionary.SetTag(SceneNameTag, tag);
			}
		}

	}
}
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: SetTag not working

Post by Tony Li »

Hi,

I'm sorry, I don't know what I was thinking. You need to update the quest instances, which are instantiated in Start(). Use something like this in your script:

Code: Select all

using System.Collections;
using PixelCrushers.QuestMachine;
using UnityEngine;

namespace AIL.Helpers
{
    public class SetSceneNameTag : MonoBehaviour
    {
        private static readonly string SceneNameTag = "{REGION}"; // Must include {..} in tag.

        private IEnumerator Start()
        {
            yield return new WaitForEndOfFrame(); // Wait for quest givers, etc., to instantiate quests.
            foreach (var questInstanceList in QuestMachine.GetAllQuestInstances().Values)
            {
                foreach (var questInstance in questInstanceList)
                {
                    questInstance.tagDictionary.SetTag(SceneNameTag, "Sample Scene");
                }
            }
        }
    }
}
random
Posts: 34
Joined: Thu May 09, 2024 10:48 pm

Re: SetTag not working

Post by random »

Well, I'm at a loss haha. I'm still getting the same results.

Updated Code:

Code: Select all

public class SetSceneNameTags : MonoBehaviour
{
	private QuestMachineConfiguration _qmConfig;

	private static readonly string SceneNameTag = "{REGION}";

	private void Awake()
	{
		_qmConfig = GetComponent<QuestMachineConfiguration>();
	}

	private void SetTagForAllQuests(QuestDatabase questDB, string tagValue, Dictionary<string, List<Quest>> questInstances)
	{
		foreach (Quest quest in questDB.questAssets)
		{
			quest.tagDictionary.SetTag(SceneNameTag, tagValue);
			string questID = quest.id.text;
			foreach (Quest questInstance in questInstances[questID])
			{
				questInstance.tagDictionary.SetTag(SceneNameTag, tagValue);
			}
		}
	}

	private IEnumerator Start()
	{
		yield return new WaitForEndOfFrame();

		Dictionary<string, List<Quest>> questInstances = QuestMachine.GetAllQuestInstances();

		foreach (QuestDatabase questDB in _qmConfig.questDatabases)
		{
			if (questDB.description == "SampleScene")
			{
				SetTagForAllQuests(questDB, "Sample Scene", questInstances);
			}
			yield return null;
		}

	}

}
random
Posts: 34
Joined: Thu May 09, 2024 10:48 pm

Re: SetTag not working

Post by random »

Ohhh, wait a minute. I'd imagine another new instance is created when a quest is added to the Quest Journal huh.

Is there some kind of event/message I can listen for when a quest instance is added/created?
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: SetTag not working

Post by Tony Li »

No worries about that. When a quest giver gives a quest to the player's Quest Journal, the quest giver clones its own quest instance and adds the clone to the Quest Journal. The clone has the same tags as the original instance.
random
Posts: 34
Joined: Thu May 09, 2024 10:48 pm

Re: SetTag not working

Post by random »

Hmm strange! Well, I guess I'll keep tinkering, hopefully I can figure out what's going on.

Appreciate the help!
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: SetTag not working

Post by Tony Li »

Are you seeing a quest that doesn't have the tags it's supposed to? Can you provide details? I've finished work for the night, but I'll check back in the morning.
random
Posts: 34
Joined: Thu May 09, 2024 10:48 pm

Re: SetTag not working

Post by random »

I am, it's the same thing happening in the pictures I posted previously. Even on newly created quest assets.

And all good!
Post Reply