Quests

Quests are often started and completed by conversing with NPCs. The Dialogue System provides an integrated quest system that makes it easy to manage quests in conversations as well as during gameplay.

Writing Quests

To see an example, you can jump down to Example Quest.

Use the Dialogue Editor's Quests/Items section to write quests.

Quest Fields

Field Description
Name The name of the quest in the dialogue database. If Use Display Name is unticked, this name is also used in UIs.
Use Display Name Tick to use a different name in UIs than the Name field.
Display Name (If Use Display Name is ticked) The name to use in UIs.
Use Groups Tick to categorize the quest in a group in UIs.
Group (If Use Groups is ticked) The group under which to categorize this quest.
Group Display Name (Optional; add Text field in All Fields section) If set, show this name for the quest group in UIs.
State The quest's starting state.
Trackable Quest can be displayed in the onscreen quest tracker HUD. The player can toggle tracking on and off.
Track On Start When quest becomes active, show it in the quest tracker HUD immediately (tracking is toggled on).
Visible (Optional; add Boolean field in All Fields section) If true, don't show in quest log window. Assumes you've ticked Check Visible Field in your Standard UI Quest Log Window.
Abandonable The player can abandon the quest.
Has Entries (Subtasks) The quest has subtasks.
Description The quest's description, shown in the quest log window when the quest is active.
Success Description The description shown when the quest is in the success state. If blank, the Description is shown.
Failure Description The description shown when the quest is in the failure state. If blank, the Description is shown.
Entry # (If Has Entries is ticked) The entry's description.
Entry # State The entry's starting state.

Markup Tags

You can use Markup Tags such as [var=varName] and [lua(code)] in quest text. This is often used in entries to show the current value of quest counters.

Localization

You can define localized versions of all text fields, such as Name, Display Name, Description, Entry #, etc., in the All Fields section or the Templates tab. For example, to add a French version of the Display Name, add a field Display Name fr.

Runtime States

The Dialogue Editor's Quests/Items section shows the design-time content of the dialogue database, not the quests' runtime states. To view runtime states during play, use the Watches tab.

Example Quest

This is one of the quests from the Dialogue System's Demo scene:

Things to note:

  • The player can toggle quest HUD tracking (Trackable), and tracking starts on (Track on Start).
  • The quest will have a different description when the player has completed it (Success Description).
  • A quest entry uses the [var=varName] markup tag to show the current count, which is maintained in a variable named enemiesKilled.

Controlling Quests

To see an example, you can jump down to Quest Management Example.

Controlling Quests in Conversations

You can generally just use the Point-and-Click Lua wizards to check and set quest states in conversations.

Quest-Related Lua Functions

If you want to use the quest management Lua functions directly, they're summarized below:

Lua Function Description Example
CurrentQuestState(questName) Returns a quest state as "unassigned", "active", "success", or "failure" CurrentQuestState("Kill 5 Rats") == "active"
SetQuestState(questName, state) Sets a quest state SetQuestState("Kill 5 Rats", "success")
CurrentQuestEntryState(questName, entryNum) Returns a quest entry state CurrentQuestEntryState("Escape", 2) == "active"
SetQuestEntryState(questName, entryNum, state) Sets a quest entry state SetQuestEntryState("Escape", 2, "success")

Note: The variables unassgined, active, success, failure, and abandoned are also defined so you can use, for example, SetQuestState("Kill 5 Rats", success) if you prefer.

Quest Management Triggers

You can control quests using these components:

Controlling Quests in Scripts

The PixelCrushers.DialogueSystem.QuestLog class provides methods to add and remove quests, get and set their state, and get their descriptions. This is a static class, so you can call its methods without having to create a QuestLog object.

Note that quest states are usually updated during conversations. In most cases, you will probably set quest states using the Point-and-Click Lua wizards during conversations, so you may never need to use many of the methods in this class.

If you do use these methods, you don't have to convert spaces and hyphens to underscores (as mentioned in Important Note About Table Indices); the QuestLog class will automatically do this for you.

Quest State Messages

The Dialogue System sends an OnQuestStateChange message when quest states change. See Script Messages & Events for details. Your scripts can use this method to monitor quest state changes. You can also hook into several QuestLog events described in the QuestLog class API reference.

Quest Management Example

In the Example Quest above, the NPC Sergeant Graves gives the player a kill quest in this conversation:

In the highlighted node, the Script field was set using the Point-and-Click Lua wizard. It does two things:

  1. Sets the quest active.
  2. Sets the Alert variable to display an alert message when the conversation ends.

Each enemy has an Increment On Destroy component that increments a variable named enemiesKilled.

The component's OnIncrement() event also runs the OnUse method of a Dialogue System Trigger on a GameObject named Enemies:

The Dialogue System Trigger's Conditions check if enemiesKilled is at least 5 and the quest is active. If so, it sets the quest to success and shows an alert message.

Authoritative Multiplayer Quests

How you manage quests in a multiplayer game highly depends the design of your game.

In many cases, you can simply maintain the Dialogue System environment (including quests) in each client for each player.

However, if you're using an authoritative master server, such as with an MMO, you may want to validate quest states on the master server to prevent cheating. To do this, assign override methods to these delegates:

  • QuestLog.SetQuestStateOverride
  • QuestLog.CurrentQuestStateOverride

In the SetQuestStateOverride method, contact the master server to confirm that the player is allowed to set the requested state. If so, call QuestLog.DefaultSetQuestState(), which will set the quest state locally, update the tracker, and inform listeners.

In the CurrentQuestStateOverride method, contact the master server to confirm the authoritative quest state for the player. The use of this method may be more complicated than SetQuestStateOverride. Communication with the master server is usually asynchronous; your override method will probably not be able to return the quest state immediately because it needs to wait for a response from the master server. Instead, your method can return a string reference to an async operation. The code that invokes CurrentQuestState() can then wait for the async operation to complete and retrieve the quest state from the response, instead of immediately using the override method's return value as the quest state.

Very often, quest states are checked and set during conversations. When using async override methods that don't return a value immediately, you may want to configure your dialogue entry's Sequence to wait for a sequencer message that indicates that the async method is done. In the dialogue entry, use the WaitForMessage() sequencer command to wait for the sequencer message. In your async method, use the Sequencer.Message() method to send the sequencer message. If the dialogue entry is configured to wait for a quest state (i.e., you've set CurrentQuestStateOverride), you can register an additional Lua function that you can use in the next dialogue entry to return the value received from the master server.

If your quests use quest entries (subtasks), you can set these overrides, too:

  • QuestLog.SetQuestEntryStateOverride
  • QuestLog.CurrentQuestEntryStateOverride

Quest UIs

Quest Log Window

The quest log window shows the details of the player's active and completed quests. The recommended way to set up a quest log window is to use the Standard UI Quest Log Window component.

Standard UI Quest Log Window

The Standard UI Quest Log Window manages the UI elements shown in the screenshot above. Those elements are:

  • Main Panel: Controls switching between showing active and completed quests.
  • Selection Panel: Shows quest headings, optionally contained inside group foldouts. The player can toggle tracking or select a quest to view its details.
  • Details Panel: Shows the details of the currently-selected quest.

All UI elements can be repositioned and reskinned.

The easiest way to set up a quest log window is to use the prefab in Prefabs ► Standard UI Prefabs ► Basic. This prefab is assigned to the Dialogue Manager prefab's Instantiate Prefabs component, which means it will automatically be instantiated under the Dialogue Manager's canvas.

The Standard UI Quest Log Window component has these properties:

Properties

Property Function
Text Table Optional text table used to localize the two Text messages below.
No Active Quests Text Text to show in the selection panel when there are no active quests.
No Completed Quests Text Text to show in the selection panel when there are no completed quests.
Check Visible Field Checks if you've defined a Boolean field named Visible in each quest and set it true; if so, doesn't show the quest in the window.
Quest Heading Source Specifies whether to use the quest's Name or Description for the heading in the selection panel.
Abandon Quest State State to set quests when the player abandons them.
Pause While Open Set Time.timeScale to 0 while the window is open.
Unlock Cursor While Open Force the cursor visible and unlocked while the window is open.
Use Groups If quests use groups, show them in group foldouts.
New Quest Text If not blank, show this text next to quest titles that haven't been viewed yet. Will be localized if text has entry in Dialogue Manager's Text Table.
Track On Quest At A Time Allow only one quest to be tracked at a time.
Deselect Quest On Second Click Clicking again on selected quest title deselects quest.
Main Panel
Main Panel The window's main panel.
Show Active Quests Heading Text label activated when showing active quests.
Show Completed Quest Heading Text label activated when showing completed quests.
Active Quests Button Button that switches mode to show active quests.
Completed Quests Button Button that switches mode to show completed quests.
Selection Panel
Quest Selection Content Container Container that will hold all instances of quest group and quest heading Templates.
Quest Group Template Template for quest group headings.
Active Quest Heading Template Template for active quest headings.
Selected Active Quest Heading Template Optional template to use for currently-selected active quest heading. If unassigned, uses Active Quest Heading Template.
Completed Quest Heading Template Template for completed quest headings.
Selected Completed Quest Heading Template Optional template to use for currently-selected completed quest heading. If unassigned, uses Completed Quest Heading Template.
Details Panel
Quest Details Content Container Container that will hold all instances of quest details templates.
Quest Heading Text Template Template for quest heading for currently-selected quest.
Quest Description Text Template Template for quest description.
Quest Entry Active Text Template Template to use for active entries.
Quest Entry Success Text Template Template to use for entries in success state.
Quest Entry Failure Text Template Template to use for entries in failure state.
Abandon Button Template Template to use for abandon button if selected quest is abandonable.
Abandon Quest Panel
Abandon Quest Panel Abandon confirmation dialog panel.
Abandon Quest Title Text Used to show name of quest in confirmation panel.

The quest log window fills in its content using templates. For example, to show the heading of an active quest in the selection panel, it instantiates a copy of Active Quest Heading Template and places it inside Quest Selection Content Container.

All of these templates are preconfigured in the Basic Standard UI Quest Log Window, so it's easiest to copy this prefab, customize its appearance, and assign your custom copy to Instantiate Prefabs instead of the Basic one.

TextMesh Pro Support

Quest log windows and quest HUDs support TextMesh Pro. To enable TextMesh Pro support, use the same steps as for TextMesh Pro Support of dialogue UIs.

Other GUI Systems

The Dialogue System still supports the older Unity UI Quest Log Window component as well as Legacy GUI, TextMesh Pro, and others in the Third Party Support folder. The older Unity UI and legacy GUI prefabs are in Prefabs ► Deprecated.

How to Show a Quest Log Window

To open the quest log window, call the Open() method. The user can close the window by clicking the Close button. To assign a hotkey that toggles the quest log window on and off, add a Quest Log Window Hotkey component.

Quest Tracker HUD

The quest tracker HUD displays the status of tracked quests during gameplay.

The recommended way to set up a quest tracker HUD is to use the Standard UI Quest Tracker component.

Properties

Property Function
Player Prefs Toggle Key PlayerPrefs key that records whether the tracker is visible or not.
Container Container that will hold instances of Quest Track Template.
Show Container If Empty Keep the container visible even if there are no tracked quests.
Quest Track Template Template for tracked quests.
Show Active Quests Show active quests in the tracker.
Show Completed Quests Show completed quests in the tracker.
Show Completed Entry Text Untick to omit full entry text for completed quests.
Quest Description Source Specifies whether to use the quest's title or description.
Visible On Start Show the tracker when the scene starts.

As with the Standard UI Quest Log Window, the easiest way to set up a quest tracker HUD is to use the prefab in Prefabs ► Standard UI Prefabs ► Basic. This prefab is assigned to the Dialogue Manager prefab's Instantiate Prefabs component, which means it will automatically be instantiated under the Dialogue Manager's canvas. Its templates are preconfigured, so you only need to customize its appearance, and assign your custom copy to Instantiate Prefabs instead of the Basic one.

Quest Indicators

You can use quest indicators to show the player that an NPC has quest information.

To set up quest indicators:

  • Add indicator GameObjects to an NPC. For example, add a Unity UI world space canvas with one or more images such as a question mark to indicate that a new quest is available, and an exclamation mark to indicate that the NPC has a quest update. In the DemoScene2 scene, the NPC Sergeant Graves has a quest indicator canvas.
  • Add a Quest State Indicator component to the NPC. This allows you to associate GameObjects, such as the world space canvas images, with numeric indicator levels. On Sergeant Graves, the indicators are:
    • Level 0: nothing
    • Level 1: question mark
    • Level 2: exclamation mark
  • Add a Quest State Listener component to the NPC. When informed of a quest state change, this component updates the Quest State Indicator's current indicator level, and optionally does other things via a UnityEvent that you can hook up in the inspector. To configure the Quest State Listener, add elements to the Quest State Indicator Levels foldout. In each element, specify a quest state and the indicator level associated with the quest state. There's also a corresponding foldout for quest entry states. The highest indicator level always takes precedence. You can add multiple Quest State Listeners if your NPC is involved in more than one quest.

To update quest state listeners if no quest state has changed – for example, if a quest field or variable has changed but not the quest's state – use the Lua function UpdateQuestIndicators("questName") or C# method QuestLog.UpdateQuestIndicators("questName");.

For a more detailed explanation with screenshots, see: How To: Set Up Quest Indicators on the forum.


<< Welcome to the Dialogue System for Unity! | Save System >>