Deserialise quest as json and programmatically add the quest

Announcements, support questions, and discussion for Quest Machine.
Post Reply
Pier
Posts: 4
Joined: Wed Nov 01, 2023 5:18 pm

Deserialise quest as json and programmatically add the quest

Post by Pier »

Hi Tony,

I have read about the quality of Pixel Crushers' support in the reviews and I am not disappointed.
Thanks for your prompt reply earlier on regarding exporting quests as json.

I have managed to export one of the quests as a json file and then I have deserialised it.

Now I have two more questions if you don't mind:

1. To deserialise the json I have created my own 'QuestData' model.

Code: Select all

QuestData questData = JsonUtility.FromJson<QuestData>(_jsonQuestData.text);
I have a feeling I am complicating my life. Do you have a better way to deserialise imported json quests?

2. Now that I can successfully retrieve every value of a quest, how can I programmatically add the quest in code. I am using C#. I have skimmed through the exhaustive documentation and this forum but I could not find any reference.

Basically what we are trying to prove to our business owners is that Quest Machine allows us to create limitless quests that can be retrieved as json files and offered to our players without need to re-deploy a new version of our application.

Thanks in advance for your help.

Kind regards,
Pier
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Deserialise quest as json and programmatically add the quest

Post by Tony Li »

Hi,

To programmatically create a quest in C#, use the QuestBuilder class. It's similar to StringBuilder but for quests. There's more info on page 65 of the manual, and there's an example script is in Quest Machine ► Templates ► QuestBuilderExample.cs.

To reconstitute a quest from JSON:

Code: Select all

var quest = Quest.CreateInstance<Quest>();
var proxy = JsonUtility.FromJson<QuestProxy>(jsonText);
proxy.CopyTo(quest);
Alternatively, you can mark the new quest assets as addressables or put them into an asset bundle. Those are both common ways to deliver new content without having to install a new version of your app/game. In this case, there's no need for JSON.
Pier
Posts: 4
Joined: Wed Nov 01, 2023 5:18 pm

Re: Deserialise quest as json and programmatically add the quest

Post by Pier »

Thanks Tony for your reply.

I believe marking new quests as Addressables is the way to go.

Kind regards,
Pier
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Deserialise quest as json and programmatically add the quest

Post by Tony Li »

Hi Pier,

Sounds good. If you run into any questions about setting it up, just ask.
Post Reply