PlayMaker

This page explains how to use Hutong Games' PlayMaker with the Dialogue System.

PlayMaker copyright © Hutong Games.


How to Set Up PlayMaker Support

To set up PlayMaker support, import the package Third Party Support/PlayMaker Support. This will add:

  1. Several actions to PlayMaker's Actions Browser under the category Dialogue System.
  2. A menu item in the Components menu for Dialogue System Events.
  3. A new sequencer command, FSMEvent().

PlayMaker Actions

The Dialogue System provides the following PlayMaker actions, listed under Dialogue System in PlayMaker's Action Browser.

Conversation Actions

Action Description
Is Conversation Active Checks whether a conversation is currently active.
Start Conversation Starts a conversation.
Stop Conversation Stops the currently-active conversation.
Does Conversation Have Valid Entries Checks whether a conversation currently has any valid entries branching from the start entry. (If all entries have conditions, it's possible that those conditions may all be false at the moment.)
Get Current Conversation Info Stores the active conversation title, ID, entry ID, actor name, and/or conversant name in variables.
Update Responses Updates the responses for the current state of the active conversation. If the response menu entries' conditions have changed while the response menu is being shown, use this to update the response menu.
Set Portrait Similar to the SetPortrait() sequencer command, this action overrides an actor's portrait image.

Bark Actions

Action Description
Bark Makes a character bark.

Sequence Actions

Action Description
Is Sequence Playing Checks whether a sequencer is currently playing.
Start Sequence Starts a sequence.
Stop Sequence Stops a sequence immediately.
Send Sequencer Message Sends a message to the sequencer. (See Example 2: Waiting for Messages)

Alert Actions

Action Description
Show Alert Shows a gameplay alert using the dialogue UI.

Quest Actions

Action Description
Add Quest Adds a quest to the quest table.
Delete Quest Deletes a quest from the quest table.
Get Quest Description Gets the description text of a quest.
Get Quest State Gets the state of a quest.
Set Quest State Sets the state of a quest.
Get Quest Entry Count Gets the number of quest entries (sub-quests) in a quest.
Add Quest Entry Adds an entry to a quest.
Get Quest Entry Gets the description of a quest entry.
Get Quest Entry State Gets the state of a quest entry.
Set Quest Entry State Sets the state of a quest entry.
Is Quest Abandonable Checks whether a quest is abandonable.
Is Quest Tracking Enabled Checks whether tracking is enabled on a quest.
Set Quest Tracking Sets tracking on or off on a quest.
Get Quest Abandon Sequence Gets the quest's Abandon Sequence (if defined).
Get Quest Count Gets the number of quests in a specified state.

Status and Relationship Actions

Action Description
Set Status Sets the status that is defined between any two assets, which is referred to as a mutual status.
Get Status Gets the mutual status defined between any two assets.
Set Relationship Sets the numerical relationship value between any two actors. Relationships can be useful for controlling NPC responses based on a relationship value.
Get Relationship Gets the relationship value between two actors.
Inc Relationship Increments the relationship value between two actors.
Dec Relationship Decrements the relationship value between two actors.

Save & Load Actions

Action Description
Apply Persistent Data Applies persistent data from the Lua environment to the objects in the scene.
Apply Savegame Data Applies savegame data to the Lua environment and the scene.
Load Level Loads a level with full Dialogue System persistent data awareness.
Load Game Loads a saved game from a string variable.
Save Game Saves a game to a string variable.
Record Persistent Data Tells objects in the scene to record persistent data into the Lua environment.
Record Savegame Data Records persistent data and extracts it as savegame data.
Reset Persistent Data Clears persistent data in the Lua environment.
Level Will Be Unloaded If you use Persistent Destructible or Increment On Destroy components, use this action before loading a new level. This tells the components to ignore their destruction due to the level change.

Note: In most cases, you'll only need to use Load Level, Load Game, and Save Game.

Database & UI Actions

Action Description
Add Dialogue Database Adds a dialogue database to the Dialogue Manager's master database.
Remove Dialogue Database Removes a dialogue database from the Dialogue Manager's master database.
Reset Dialogue Database Resets the Dialogue Manager's master database to an initial state.
Set Default Dialogue Database Sets the default database to use for the Dialogue Manager's master database.
Preload Master Database Normally the master database is loaded just before being used by the first conversation, bark, or quest update. Use this action to load it immediately.
Preload Dialogue UI Normally the dialogue UI is loaded just before being used for the first time. Use this action to load it immediately.
Set Dialogue UI Assigns a different dialogue UI to use for conversations and alerts.

Lua / Internal Data Actions

Action Description
Run Lua Runs arbitrary Lua code.
Get Variable Gets the value of a variable in the Lua Variable[] table.
Set Variable Sets the value of a variable in the Lua Variable[] table.
Get Lua Field Gets the value of a field of an element in a Lua table (Actor[], Item[], or Location[]).
Set Lua Field Sets the value of a field of an element in a Lua table (Actor[], Item[], or Location[]).
Sync type Syncs the value of a variable between PlayMaker and the Dialogue System's Variable[] table. (Similar to Get/Set Variable)

Other Actions

Action Description
Set_Language Sets the current language to use for localization.
Get Localized Text Gets the value of a localized table table field using the current language.
Get Actor Name Gets a GameObject's actor name or internal Lua index name.

See Localization for information about localized text tables.

Example Action - Conversation

Below is a screenshot of an example FSM on an NPC that starts a conversation when the player enters the NPC's trigger collider:

The conversation title "Quick Start" should be present in your dialogue database.

Note that the player is assigned as the Actor. Since the FSM is on the NPC, you don't need to specify the Conversant; it will default to the NPC.


Using Lua Actions

This section describes how to use actions to access data in the Dialogue System's Lua environment.

About Dialogue System Lua Tables

The Variable[] table is one-dimensional. That is, every variable (such as Variable["Actor"]) has only one value. Variable["Actor"].Age isn't valid. Variable["Actor"] and Variable["Conversant"] are string values. Variable["Actor"] contains the name of the actor in the current conversation, and Variable["Conversant"] contains the name of the conversant.

The Actor[], Item[]/Quest[], and Location[] tables are two-dimensional. Every entry, such as Actor["Player"] has a number of fields such as Actor["Player"].Age.

Accessing Dialogue System Lua Data

Let's say you know the name of an actor ("Fred"), and you want to get his age. In the Dialogue System's Lua environment, this is stored in Actor["Fred"].Age, and this is what you'll use in the Dialogue Editor in Conditions and Script fields.

In PlayMaker, you can use the Get Lua Field action. Select the Actor Table and manually enter "Fred" as the element and "Age" as the Field. In the example below, the result is stored in a float variable named "Freds Age".

If you're in the middle of a conversation and you don't know ahead of time who the actor is, you can first get the value Variable["Actor"] by using the Get Variable action. In the example below, it's stored in a string variable named "Current Actor Name". Then you can provide the string variable's value to the Get Lua Field action.

The Set Lua Field and Set Variable actions work similarly but come with one important caveat. Lua is essentially typeless. You can assign a number to Actor["Fred"].Age, and then you can turn around and assign a string to it. Of course, a string probably wouldn't make sense in context, but in Lua you can still do it if you want. The PlayMaker action will assign any/all values that you've specified. In the example below, to prevent the action from trying to assign a string or bool value, the string and bool properties have been set to "None" by clicking the little button to the right of each one.

If Bool Value had been left as false, Actor["Fred"].Age would have been assigned the value 99, and then it would have been assigned the value false.

Similarly, you should remember to set the unused values to None in the Set Variable action. Also note that "Variable Name" for the Variable[] table is equivalent to "Element" for the Actor[] table. It's the value inside the square brackets. These values are typically called indices, since they provide an index into the table. The action below sets Variable["Another Variable"] to 42.

There's one more thing to note about Lua in the Dialogue System: spaces (' ') and hyphens ('-') in indices are replaced by underscores ('_'). So in your Conditions and Script fields, you should use Variable["Another_Variable"]. (Note the underscore.)


PlayMaker Events

If you want your FSM to receive Dialogue System events, add a Dialogue System Events To PlayMaker component to a GameObject in your scene that will receive Script Messages. This is usually the Dialogue Manager GameObject, but it can also be a conversation participant. To do add the component, select Component > Dialogue System > Third Party > PlayMaker > Dialogue System Events To PlayMaker.

This component will pass Dialogue System notification messages such as OnConversationStart and OnConversationEnd to any FSMs that you've assigned to the component's FSMs list. The message events are:

Event Description
OnConversationStart Sent at the start of a conversation. The event's GameObject data is the other participant in the conversation (or the primary actor if the component is on the other participant)
OnConversationEnd Sent at the end of a conversation. The event's GameObject data is the other participant in the conversation
OnConversationCancelled Sent at the end of a conversation. The event's GameObject data is the other participant in the conversation
OnConversationLine Sent whenever a line is spoken
OnConversationLineCancelled Sent if the player presses the cancel key/button while a line is being delivered. Cancelling causes the Dialogue System to jump to the end of the line and continue to the next line or response menu
OnConversationResponseMenu Sent just prior to setting up the response menu with responses. If you specify a separator (e.g., ';') in the Event Data section, the event's String data will be the Menu Texts separated by that separator
OnConversationTimeout Sent to the Dialogue Manager object (not the participants) if the response menu times out
OnLinkedConversationStart Sent when the current conversation follows a cross-conversation link. The event's GameObject data is the other participant in the conversation
OnBarkStart Sent at the start of a bark. The event's GameObject data is the other participant
OnBarkEnd Sent at the end of a bark. The event's GameObject data is the other participant
OnSequenceStart Sent at the start of a sequence. The event's GameObject data is the other participant
OnSequenceEnd Sent at the end of a sequence. The event's GameObject data is the other participant
OnQuestStateChange Sent when a quest state or quest entry state changes. The event's String data is the name of the quest
OnQuestTrackingEnabled Sent when tracking is enabled for a quest. The event's String data is the name of the quest
OnQuestTrackingDisabled Sent when tracking is disabled for a quest. The event's String data is the name of the quest
OnRecordPersistentData Sent when the Dialogue System is recording persistent data into the Lua environment, usually when saving a game or before changing levels
OnApplyPersistentData Sent when the Dialogue System is applying persistent data to the scene from the Lua environment, usually when loading a game or after changing levels
OnLevelWillBeUnloaded Sent prior to unloading a level, usually before changing levels
OnDialogueSystemPause Sent when the Dialogue System is paused
OnDialogueSystemUnpause Sent when the Dialogue System is unpaused

You can also use the sequencer command FSMEvent() to send events from sequences to FSMs.


PlayMaker Sequencer Commands

The PlayMaker Support package adds the sequencer command below.

FSMEvent()

Syntax: FSMEvent(event[, subject|all[, fsm]])

Description: This sequencer command sends an event to a PlayMaker FSM on a subject.

Parameters:

  • event: The name of the event.
  • subject: (Optional) The owner of the FSM. Default: speaker. If you use the keyword all for the subject, it will send the event to all FSMs on all GameObjects in the scene.
  • fsm: (Optional) The FSM to send the event to. If omitted, the event is sent to all FSMs on the subject.

Example:

  • FSMEvent(Updated Name Variable, Player) (Sends an event "Updated Name Variable" to the FSM(s) on the object named "Player".)

How to Set Up FSMEvent

The FSMEvent() sequencer command sends an event to an FSM. Here are the steps to set it up. These steps use the example scene in the PlayMaker Support package to demonstrate. This scene has an FSM on the Dialogue Manager object.

  1. Define an event in your FSM using the Events tab on the right-hand side of the PlayMaker Editor. For example, define an event called "Test Sequence Ended".
  2. Configure a state to transition when it receives this event. In this example, we'll configure a state at the bottom of the FSM called "Test Sequence". It transitions back to the "Root" state when it receives the "Test Sequence Ended" event.
  3. In your Sequence, call FSMEvent(eventName, gameObject, fsmName). This will send an event named eventName to an FSM named fsmName on a specific gameObject.
    • If you leave out fsmName, it will send the event to all FSMs on the gameObject.
    • If you leave out gameObject, it will send the event to the speaker.

The example scene, the "Test Sequence" state does a little fade out/fade in sequence and, at the 2 second mark, calls FSMEvent(Test Sequence Ended). This sends the event "Test Sequence Ended" to all FSMs on the speaker, which in this case is defined to be the Dialogue Manager object itself.

In your project, you could do something like this:

TextInput(MyTextInputUI,Name,PlayerName)->Message(GotName); FSMEvent(SetName,PlayerManager)@Message(GotName)

The first command gets the text input. When it's done, it sends the message "GotName" to the sequencer.

The second command waits until it receives the message "GotName". Then it sends the "SetName" event to the PlayerManager.

In your PlayerManager FSM, set up a transition for the SetName event. When you receive this event, use the Get Variable action to get the value of PlayerName. Then use the Game Object Set Name action to set the game object's name to PlayerName.

Side Note: In practice, for this specific scenario, you could just put "[var=PlayerName]" in the Actor Override Name component to do the same thing.


PlayMaker Lua Functions

Dialogue entry nodes' Script and Conditions fields accept Lua functions, as can the Lua Trigger component. To make PlayMaker-specific Lua functions available, add the component Dialogue System PlayMaker Lua to your Dialogue Manager. This will add these functions to Lua:

Event Functions

The FSMEvent() Lua function sends an event to FSM(s).

FSMEvent(eventName:string, objectName:string, fsmName:string)

Lua Function Description
FSMEvent(eventName:string, objectName:string, fsmName:string) Sends an event to an FSM.

This sequencer command sends the event eventName to the GameObject named objectName, and specifically to the FSM named fsmName.

If fsmName is blank, the event is sent to all FSMs on the GameObject. If objectName is blank, the event is sent to all GameObjects that have FSMs.

Variable Functions

The Lua functions below allow you to get and set PlayMaker global variables.

Lua Function Description
GetFsmFloat(variableName:string) Returns the value of a global float variable.
GetFsmInt(variableName:string) Returns the value of a global int variable.
GetFsmBool(variableName:string) Returns the value of a global bool variable.
GetFsmString(variableName:string) Returns the value of a global string variable.

Lua Function Description
SetFsmFloat(variableName:string, value:float) Sets the value of a global float variable.
SetFsmInt(variableName:string, value:int) Sets the value of a global int variable.
SetFsmBool(variableName:string, value:bool) Sets the value of a global bool variable.
SetFsmString(variableName:string, value:string) Sets the value of a global string variable.

<< Third Party Support