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.
How to attach 'UserData' to a Quest(or Quest Node)?
Re: How to attach 'UserData' to a Quest(or Quest Node)?
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.
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)?
Is it correct to use like this?
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?
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);
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)?
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.
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)?
Most likely a ScriptableObject...
Re: How to attach 'UserData' to a Quest(or Quest Node)?
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:
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)?
Thank you for answer!
Re: How to attach 'UserData' to a Quest(or Quest Node)?
Glad to help!