Code: Select all
public string questTitleToAdd;
public string questDescriptionToAdd;
public QuestState questStateToAdd;
public DialogueDatabase database;
[ContextMenu("Add Quest")]
public void AddAQuest()
{
Item item = database.GetItem(questTitleToAdd);
if (item != null)
{
Debug.Log("Quest already exists");
return;
}
var template = TemplateTools.LoadFromEditorPrefs();
var quest = template.CreateQuest(template.GetNextQuestID(database), questTitleToAdd);
quest.fields.Find(f => f.title == "Description").value = questDescriptionToAdd;
quest.fields.Find(f => f.title == "State").value = questStateToAdd.ToString(); //without this it's show as Unassign in inspector
database.items.Add(quest);
//Both don't seem to do anything
//DialogueLua.SetQuestField(quest.Name, "State", questStateToAdd.ToString());
//DialogueLua.SetQuestField(quest.Name, "State", questStateToAdd);
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(database);
UnityEditor.AssetDatabase.SaveAssets();
#endif
if (DialogueEditorWindow.instance != null) DialogueEditorWindow.instance.Reset();
//Check state value => correct
foreach (var checkQuest in database.items)
{
if (checkQuest.IsItem) continue;
var stateField = checkQuest.fields.Find(f => f.title == "State");
Debug.Log($"Quest: {checkQuest.Name}, State: {stateField.value}");
}
}
According to the debug snippet at the bottom, the printed state value is correctly assigned (it shows the value of questStateToAdd). So I think the issue was with the Inspector, but I can't figure out what’s wrong

(By the way, this function (along with another function that read quests from database) is meant to sync (push or pull) my custom quest system with this dialogue system. My quest system is just a simple GraphView with color-coded nodes and connections that determine which quests unlock others—really easy for me to debug and get a big-picture view. But I haven’t found much information on adding quests through scripts, so I’m not sure if what I’m doing is the right approach, haha.)
Edit: I found the problem—you need to add .ToLower()
=> quest.fields.Find(f => f.title == "State").value = questStateToAdd.ToString().ToLower()