[Resolved] Set Quest Journal ID's at runtime

Announcements, support questions, and discussion for Quest Machine.
Post Reply
thebiscuit
Posts: 2
Joined: Sun Sep 29, 2019 6:28 am

[Resolved] Set Quest Journal ID's at runtime

Post by thebiscuit »

Hi all,

I'm working on a project where we are using Questmachine, LoveHate and the Dialogue System together.

We are looking to generate a number of NPC's with quest journals at runtime and then have them run around completing quests that will be generated for them (whilst having opinions about the other characters thanks to LoveHate).

As part of character generation, I'm wanting to access the "Quest Journal" component as each character is created and set a unique value for "ID" and "Display Name".

I'm struggling to set the "ID" field in the quest journal (although I suspect that I'm overlooking something obvious :|).

Here is the current code from the script in question as it stands:

Code: Select all

using UnityEngine;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using PixelCrushers.QuestMachine;

... //tl;dr unrelated code

            GameObject newHero = Instantiate(heroPrefab);
            heroList.Add(AddGroundObjectAtPosition(cityPosition, newHero));
            string newID = ("hero " + heroList.Count);
            QuestJournal tempJournal = newHero.GetComponent<QuestJournal>();
            tempJournal.id.stringAsset.text = newID; //NullReferenceException fires on this line 
            
...            
I've attempted to set the id variable using a variety of methods before this but haven't figured out a way yet.

Any advice would be appreciated.

Biscuit
Last edited by thebiscuit on Sun Oct 06, 2019 2:35 am, edited 1 time in total.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Quest Journal ID's at runtime

Post by Tony Li »

Hi,

After assigning the ID, call AssignGiverIDToQuests() to associate each of the hero's quests with its new ID.
thebiscuit
Posts: 2
Joined: Sun Sep 29, 2019 6:28 am

[Resolved]Re: Set Quest Journal ID's at runtime

Post by thebiscuit »

Thanks for coming back so fast, that got me back on the right track.

Also noticed to my embarrassment that I forgot to add "using PixelCrushers;" meaning that I couldn't play with the StringField datatype like I needed to.

Marking resolved :).
Post Reply