Page 1 of 2
SetTag not working
Posted: Tue Jul 09, 2024 7:50 pm
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);
}
}
Re: SetTag not working
Posted: Tue Jul 09, 2024 9:01 pm
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.
Re: SetTag not working
Posted: Tue Jul 09, 2024 9:30 pm
by random
Unfortunately, I'm not sure why it isn't working correctly.
- Screenshot 2024-07-09 213000.png (14.68 KiB) Viewed 1308 times
- Screenshot 2024-07-09 212951.png (10.05 KiB) Viewed 1308 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);
}
}
}
}
Re: SetTag not working
Posted: Tue Jul 09, 2024 9:58 pm
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");
}
}
}
}
}
Re: SetTag not working
Posted: Tue Jul 09, 2024 10:21 pm
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;
}
}
}
Re: SetTag not working
Posted: Tue Jul 09, 2024 10:30 pm
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?
Re: SetTag not working
Posted: Tue Jul 09, 2024 10:35 pm
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.
Re: SetTag not working
Posted: Tue Jul 09, 2024 10:39 pm
by random
Hmm strange! Well, I guess I'll keep tinkering, hopefully I can figure out what's going on.
Appreciate the help!
Re: SetTag not working
Posted: Tue Jul 09, 2024 10:47 pm
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.
Re: SetTag not working
Posted: Tue Jul 09, 2024 10:56 pm
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!