Create a Custom Quest Condition

v4.0

It is not difficult to create custom Quest Condition scripts. Often your game will have unique mechanics, and you may wish to include those in condition comparisons.

Read on to learn more about the anatomy of a Quest Condition Inspector, or visit the pages below to create the required scripts, and then code your first custom Quest Condition.

pageYour Quest ConditionpageYour Quest Condition EditorpageYour Quest Condition Drawer

Anatomy of a Quest Condition Inspector

Each Quest Condition may have a different inspector. I've created custom Inspectors for each of the Quest Conditions that ship with Game Modules, however custom Inspectors are not required -- they're just a convenience and look prettier.

We will be looking at the BlackboardValueNumber condition.

This is a "BlackBoardValueNumber" QuestCondition, which I've named "Gold is 100 or More". The top portion is the custom Inspector, while the bottom portion is the default Inspector. Both accomplish the same thing, and have the same fields exposed.

If you create custom Quest Conditions, you can create custom Inspectors, or not -- entirely up to you. If you do choose to create custom Inspectors, you can follow the same pattern explained here.

There are three scripts that make up a fully formed Quest Condition which can be viewed in the Editor with a custom Inspector. See full details about creating your own on the pages nested in this section.

Class which inherits from QuestCondition

The BlackboardValueNumber class inherits from QuestCondition. This is the class which performs the actual comparison evaluation. The derived class has the opportunity to override a number of methods on the base class, and are required to have their own version of ConditionMet().

// Each derived class is required to have this method
public abstract bool ConditionMet(BlackboardNote blackboardNote);

// These can be overridden
public virtual bool ConditionMet<T>(QuestStep questStep, T obj)
public virtual void SaveCurrentValue(GameQuest gameQuest, QuestStep questStep)
public virtual float TrueValue()
public virtual void CompleteQuest()

Editor Class

The BlackboardValueNumberEditor class inherits from QuestConditionEditor, and is the script which tells Unity to draw a custom Inspector when the BlackboardValueNumber object is being viewed.

It overrides the CreateDrawer() method, and nothing else. While it does not seem like much, it is required for displaying the custom Inspector.

protected override QuestConditionDrawer CreateDrawer()
{
    questConditionDrawer = ScriptableObject.CreateInstance<BlackboardValueNumberDrawer>();
    return questConditionDrawer;
}

Drawer Class

Finally the BlackboardValueNumberDrawer class inherits from QuestConditionDrawer. This is the class which does the actual drawing of the custom Inspector.

This is using the static class InfinityPBR.InfinityEditor, which you can also use to make your own custom Inspectors.

public override bool CanHandle(QuestCondition questCondition) 
    => questCondition is BlackboardValueNumber;
        
protected override void ShowSpecificData(QuestCondition questCondition) 
    => ShowData(questCondition as BlackboardValueNumber);
{
    // Draw Stuff....
}

Last updated