Page 1 of 1

[Resolved] Set Quest Journal ID's at runtime

Posted: Sun Sep 29, 2019 6:43 am
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

Re: Set Quest Journal ID's at runtime

Posted: Sun Sep 29, 2019 10:29 am
by Tony Li
Hi,

After assigning the ID, call AssignGiverIDToQuests() to associate each of the hero's quests with its new ID.

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

Posted: Sun Oct 06, 2019 2:31 am
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 :).