How to attach 'UserData' to a Quest(or Quest Node)?

Announcements, support questions, and discussion for Quest Machine.
Post Reply
nuununuun
Posts: 13
Joined: Thu Dec 17, 2020 11:54 pm

How to attach 'UserData' to a Quest(or Quest Node)?

Post 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.

:roll:
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to attach 'UserData' to a Quest(or Quest Node)?

Post 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.
nuununuun
Posts: 13
Joined: Thu Dec 17, 2020 11:54 pm

Re: How to attach 'UserData' to a Quest(or Quest Node)?

Post 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?
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to attach 'UserData' to a Quest(or Quest Node)?

Post 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.
nuununuun
Posts: 13
Joined: Thu Dec 17, 2020 11:54 pm

Re: How to attach 'UserData' to a Quest(or Quest Node)?

Post by nuununuun »

Most likely a ScriptableObject... :roll:
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to attach 'UserData' to a Quest(or Quest Node)?

Post 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;
nuununuun
Posts: 13
Joined: Thu Dec 17, 2020 11:54 pm

Re: How to attach 'UserData' to a Quest(or Quest Node)?

Post by nuununuun »

Thank you for answer! :D
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to attach 'UserData' to a Quest(or Quest Node)?

Post by Tony Li »

Glad to help!
Post Reply