Page 1 of 1
How to attach 'UserData' to a Quest(or Quest Node)?
Posted: Tue May 02, 2023 2:58 am
by nuununuun
Hi,
I want to keep and use userdata (ex. quest reward data) with the quest.
Is there any way I can do to achieve this?
If possible, I'd like to be able to attach this to a Quest asset.
Re: How to attach 'UserData' to a Quest(or Quest Node)?
Posted: Tue May 02, 2023 8:36 am
by Tony Li
Hi,
Yes, you can for example write a custom quest action and add it to the quest's Success node(s). Your custom quest action script can hold user data. To make a custom quest action, duplicate QuestActionTemplate.cs and rename the duplicate to YourActionNameQuestAction.cs, where YourActionName is the name you want to give to the open. Then edit the script, rename the class to YourActionName, and add your code where the comments indicate.
Re: How to attach 'UserData' to a Quest(or Quest Node)?
Posted: Tue May 02, 2023 10:33 pm
by nuununuun
Is it correct to use like this?
Code: Select all
public class SampleQuestAction : QuestAction
{
[field: SerializeField] public string HelloWorld { get; private set; }
// omitted ...
Code: Select all
var sampleQuestAction = quest.GetStateInfo(quest.GetState()).actionList.OfType<SampleQuestAction>().FirstOrDefault();
Debug.Log(sampleQuestAction?.HelloWorld);
Is there any better way?
and,
I want to have common userdata no matter what state the quest is in. In this case, can I just set a rule (ex. always put quest reward data in WaitingToStart) and use it?
Re: How to attach 'UserData' to a Quest(or Quest Node)?
Posted: Tue May 02, 2023 10:58 pm
by Tony Li
I suggested a custom quest action on the Success node because that's when the player will receive the reward.
If you need to attach other kinds of data, what kinds of data are they?
If it's just strings, you could add it to the quest's
labels list. You can edit the labels list in the quest's main info section.
Re: How to attach 'UserData' to a Quest(or Quest Node)?
Posted: Tue May 02, 2023 11:55 pm
by nuununuun
Most likely a ScriptableObject...
Re: How to attach 'UserData' to a Quest(or Quest Node)?
Posted: Wed May 03, 2023 8:32 am
by Tony Li
In that case, you can write a custom QuestAction or QuestContent to put store a reference to the ScriptableObject asset in the main quest info's Actions or a UI content section.
For example, say you create a script named MyCustomDataQuestAction and put it in the quest's Active state > Actions section. Then you can get it like this:
Code: Select all
var activeState = quest.GetStateInfo(QuestState.Active);
var actionList = activeState.actionList;
var myAction = actionList.Find(action => action is MyCustomDataQuestAction);
var myData = myData.customData;
Re: How to attach 'UserData' to a Quest(or Quest Node)?
Posted: Thu May 04, 2023 1:50 am
by nuununuun
Thank you for answer!
Re: How to attach 'UserData' to a Quest(or Quest Node)?
Posted: Thu May 04, 2023 7:53 am
by Tony Li
Glad to help!