RPG Kit

(Click Here for Video Tutorial)

This page will show you how to integrate the Dialogue System with Unitycoding's RPG Kit to add conversations, barks, cutscene sequences, and Dialogue System-managed quests. (RPG Kit 3.1.5+ is required.)

RPG Kit copyright © Unitycoding.


RPG Kit Support Features

The support package adds these features:

  • New dialogue UI and quest log window that match RPG Kit's built-in Unity UI interface.
  • A bridge that synchronizes RPG Kit data with the Dialogue System's Lua environment.
  • Lua functions that you can use in conversations to get and set state RPG Kit values.
  • Automatic saving and loading of Dialogue System data, including quest states.

The package also depends on the ICode support package.

IMPORTANT: Please read the RPG Kit Setup section! You must follow a few very specific steps get the Dialogue System working with RPG Kit.

For general gameplay integration topics, see How to Integrate with Gameplay.


RPG Kit Setup

You must follow these steps to set up the Dialogue System in RPG Kit.

  1. Import the package Third Party Support/ICode Support. This will unpack files into the folder Third Party Support/ICode.
  2. Import the package Third Party Support/RPG Kit Support. This will unpack files into the folder Third Party Support/RPG Kit.
  3. There are two ways to set up the dialogue UI:
    • Option 1: In your project's Build Settings (File > Build Settings), remove the Loading scene and replace it with the Loading scene found in Third Party Support/RPG Kit/Example. This is a customized version of RPG Kit 3.1.7's Loading scene. If you're using a newer version of RPG Kit and it has a newer Loading scene, you may want to use Option 2 below.
    • Option 2: Open RPG Kit's Loading scene.
      • Add the prefab Third Party Support/RPG Kit/Prefabs/Dialogue Manager to the scene.
      • If you want the quest journal button to open the Dialogue System's quest log window, inspect the GameObject UI/Actionbar/Open Quest. In the Button component's OnClick() section, click the "+" button to add an entry. Then assign Dialogue Manager/Canvas/Quest Log Window to the entry, and select the method "UIWidget.Toggle" (see below). NOTE: This used to be called "UIWindow.Toggle"; the screenshot below shows the old name; use UIWidget.Toggle now.
      • The Canvas located inside the Dialogue Manager contains a dialogue UI, quest tracker HUD, and quest log window. If you don't plan to use the Dialogue System's quest system, you can deactivate the quest tracker HUD and quest log window GameObjects.
      • The dialogue UI uses a subclass of Unity UI Dialogue UI that redirects alert messages to RPG Kit's message system.
  4. Open your Loading scene, and assign your dialogue database to the Dialogue Manager. By default, the Dialogue Manager prefab points to the example database included with the support package.
  5. If you want to add the example NPCs, add the prefabs in Third Party Support/RPG Kit/Example/NPCs to RPG Kit's Main Level scene.
    • Barker: Demonstrates barks.
    • Converser: Demonstrates conversations, quests, items, shop, healing, and giving gold.

Quest Log Window Button

The screenshot below shows how to manually connect the Dialogue System's quest log window to RPG Kit's action bar:

You don't need to do this if you used Option 1 above (the Dialogue System's customized Loading scene) because it already includes this step.


How to Configure Barks and Conversations

How to Configure Barks

To make an NPC bark, follow the instructions on these pages:

  1. Add a Unity UI Bark UI to the NPC.
  2. Add or modify the NPC's state machine to invoke the Bark action. If your NPC doesn't have a state machine yet, you can add Third Party Support/RPG Kit/Example/State Machines/Bark StateMachine.
  3. Create a bark state.
    1. Set the Bark action's Conversation property to the name of the bark conversation in your dialogue database.
    2. Set the Actor and Conversant to the participants. The Actor should be the NPC itself. The Conversant may be null if the NPC is just barking into the air.
    3. Since a bark is a one-off action, you can transition immediately back to the previous state.

The support folder's Barker prefab uses Unity UI Bark UI. When you add the Barker prefab to your scene and expand it, you'll see a child GameObject named Basic Unity UI Bark UI. Inspect this GameObject. On the Canvas Group component, set Alpha to 1. Then customize the appearance to your liking.

When you're ready to make a build for players, set Alpha back to 0. The game will still run fine if you don't set it to 0, but the bark will flicker when appearing and disappearing.

How to Configure Conversations

The easiest way to make an NPC engage in conversation is to add an RPG Kit Conversation Trigger component to the NPC (Component > Dialogue System > Third Party > RPG Kit > RPG Kit Conversation Trigger).

Alternatively, you can use an ICode state machine:

-Add or modify the NPC's state machine to invoke the Start Conversation action. If your NPC doesn't have a state machine yet, you can add Third Party Support/RPG Kit/Example/Conversation StateMachine.

  1. Create a conversation state.
    1. Add a Conversation action, and set its Conversation property to the name of the conversation in your dialogue database.
    2. Set the Actor and Conversant to the participants (usually the player and the NPC).
    3. Transition back on the condition IsConversationActive is false.

How to Configure Shop and Quest Conversations

This is the easiest way to configure an NPC with a shop and a conversation:

  1. Add an RPG Kit Conversation Trigger to the NPC.
  2. Add an RPG Kit Store Trigger No Out Of Range Message to the NPC. Set its Distance to 0. This is the same component as RPG Kit's Store Trigger except it doesn't show a "too far" message when you click on the NPC. (Since you've set the Distance to 0, all distances will be out of range for this trigger. This is so the RPG Kit Conversation Trigger will be able to grab control first.)
  3. In the conversation, call OpenShop("Conversant") in a response menu entry (blue node). For more details about the OpenShop Lua function, see Using OpenShop.

Alternatively, you can configure shops to use your NPC's state machine. Follow these steps to make an NPC switch from a conversation to the shop:

  1. In your NPC's state machine, add a state called Shop. It's easiest to start with the example Shop NPC's state machine, since this already has all the actions necessary to open and close the shop window. You'll just want to get rid of the OnClick transition, since presumably OnClick will transition to your conversation state instead.
  2. Create a Boolean parameter called OpenShop. Leave it false (unticked).
  3. Create a transition from your conversation state to the Shop state. The condition for this transition is that OpenShop is true. Your state machine should now look something like this:
  4. In the dialogue entry that switches to the shop, use this sequence command:
SetStateBool(this, OpenShop, true)

How to Configure Overhead Icons

Overhead icons are often used to indicate that an NPC has a quest.

The easiest way to set up an NPC with overhead icons is to add the prefab Example/NPCs/Animation/Overhead Icon UI to your NPC. This UI comes with question mark and exclamation mark icons.

You can set up your own icons by following these steps:

  1. Set up a world space UI (or just copy Overhead Icon UI).
  2. Add your icons to that UI.
  3. Add an Animator with an animator controller if you want to animate the UI. The provided prefab also has a Look At Main Camera component. If you want to keep the UI facing the camera instead of animating it, disable the Animator and enable the Look At Main Camera.
  4. Add an Overhead Icon Controller component. Assign the icons to the component.

How to Change Overhead Icons at Runtime

To change an icon, you can any use any of these methods:

  • Set Overhead Icon ICode action
  • SetOverheadIcon(iconName, [subject]) sequencer command (default subject is speaker), or
  • SetOverheadIcon(subject, name) Lua command. (Note that the parameter order is reversed for the Lua command.)

For example, use this sequencer command to show an exclamation above the NPC named "Converser":

SetOverheadIcon(Exclamation, Converser)

Note that if you use the Lua command, you should wrap the strings in double quotes:

SetOverheadIcon("My NPC Name", "Question")

Use "none" as the icon name to hide all icons.

Icon Conditions

Use the Icon Conditions section to specify which icon (if any) should be visible when the NPC starts and when the player levels up:

The Overhead Icon UI will process the list of Icon Conditions from top to bottom, so Icon Conditions that are lower in the list can override earlier ones. When you add an element to the Icon Conditions list, specify the icon and the conditions that must be true to show it.

If you've specified any Icon Conditions, the Starting Icon will be ignored in favor of the Icon Conditions.


Saving & Loading

The Dialogue System currently saves its data to PlayerPrefs in single-player and multi-player modes. This includes all the standard Save System data, such as variable values and quest states.

It loads data:

  • When the character enters the game.

It saves data:

  • After every conversation involving the player.
  • When the "UpdateTracker" message is sent to the Dialogue Manager (typically when quest data changes).
  • If you use the ICode "Dialogue System/RPG/Save Data" action in one of your state machines.

RPG Kit - Dialogue System Bridge

The RPG Kit Bridge component is on the Dialogue Manager GameObject in the Loading scene.

The RPG Kit Bridge component does the following:

  • Suspends player gameplay control during conversations.
  • Copies the player's name and class to Lua at the start of conversations.
  • NOTE: The bridge does not sync items and attributes. Use the RPG Kit Lua functions instead.

The following data are synchronized:

Lua Data Notes
Actor["Player"].PlayerName Read-only
Actor["Player"].Gender Read-only
Actor["Player"].Class Read-only
Actor["Player"].Level Read-only

You can also call these static methods manually:

Method Description
RPGKitBridge.SetPlayerControl(bool) Enables or disables player movement and camera control
RPGKitBridge.SyncToLua() Copies RPG Kit data (player name, gender, class, level) into the Lua environment
RPGKitBridge.SyncFromLua() Copies the Lua environment back into RPG Kit (currently does nothing)
RPGKitBridge.SaveDialogueSystemData() Saves the current character's Dialogue System data

Or in state machines use the ICode actions Dialogue System > RPG > SyncLuaToRPG and SyncRPGToLua. (See the RPG Kit ICode Actions section for a complete list of new actions.)


RPG Kit Lua Functions

Lua Function Returns Description Example
GetPlayerName() String Get player's name GetPlayerName()
GetPlayerGender() String Get player's gender GetPlayerGender()
GetPlayerClass() String Get player's class GetPlayerClass()
GetPlayerLevel() Number Get player's level GetPlayerLevel()
GetPlayerStatus(statusName) Number Get status value on player GetPlayerStatus("Health")
ModifyPlayerStatus(statusName, amount) N/A Modify status value on player ModifyPlayerStatus("Health", -10)
GetEntityStatus(gameObjectName, statusName) Number Get status value on entity GetEntityStatus("King", "Hunger")
ModifyEntityStatus(gameObjectName, statusName, amount) N/A Modify status value on entity ModifyEntityStatus("King", "Hunger", 20)
PlayerHasItem(itemName, amount) Boolean Check player has amount of item PlayerHasItem("Axe", 1)
PlayerAddItem(itemName, amount) N/A Give item to player PlayerAddItem("Gold", 50)
PlayerRemoveItem(itemName, amount) N/A Remove item from player PlayerRemoveItem("Nail", 3)
EntityHasItem(itemName, amount) Boolean Check entity has amount of item EntityHasItem("King", "Axe", 1)
EntityAddItem(itemName, amount) N/A Give item to the entity EntityAddItem("King", "Gold", 50)
EntityRemoveItem(itemName, amount) N/A Remove item from entity EntityRemoveItem("King", "Nail", 3)
OpenShop(gameObjectName) N/A Open StoreTrigger (see note) OpenShop("Conversant")
SetOverheadIcon(gameObjectName, iconName) N/A Set an NPC's overhead icon ("none" for no icon) SetOverheadIcon(Converser, Question)

Using OpenShop

To use OpenShop(), add a StoreTrigger to the NPC, and set its Distance to 0.

Note: If you pass "Actor" to OpenShop(), it will open the StoreTrigger on the current actor (if a conversation is active). If you pass "Conversant" or a blank string (""), it will open the StoreTrigger on the current conversant. Otherwise it will look for a matching GameObject in the scene.


RPG Kit ICode Actions

The RPG Kit support package adds the following actions under "Dialogue System/RPG":

Action Description
Delete Data Delete the Dialogue System saved data for a specific character
Open Shop Open an NPC's shop
Save Data Save the current character's Dialogue System data (quests, etc.)
Set Overhead Icon Change an NPC's overhead icon
Sync Lua To RPG Sync the Dialogue System's Lua values to RPG Kit (currently does nothing)
Sync RPG To Lua Sync RPG Kit's values to the Dialogue System's Lua environment
Update Quest Tracker Update the Dialogue System's quest tracker HUD

<< Third Party Support