How to Integrate with Gameplay

This page contains a discussion of how to integrate "conversation mode" with your project's regular "gameplay mode."


About Gameplay Integration

When setting up your project infrastructure, integrating PC-NPC dialogue with gameplay is one of the more complicated tasks, because you need to transition player control from gameplay mode (looking around, moving, etc.) to conversation mode. Generally, you need to temporarily disable gameplay controls and NPC AI, and get the NPC to act the way you want in conversation mode.
To do this, you can use triggers such as Set Enabled On Dialogue Event and/or sequencer commands such as SetEnabled().

The general approach is:

  1. Identify the control, camera, and AI components that are active during gameplay.
  2. When the conversation starts, disable these components and enable any necessary conversation mode components. For example, if you use a Mecanim Animator to control your character in gameplay but a legacy Animation component to control your character in dialogue cutscene sequences, you'll want to disable the Animator and enable the Animation component. (Note: If you've assigned a Sequencer Camera in the Dialogue Manager's display settings, the Dialogue System will automatically disable the gameplay camera and enable the sequencer camera.
  3. When the conversation ends, disable any conversation-only components and re-enable the gameplay components.

In addition, you may need to share data between the Dialogue System and your gameplay framework (for example, the player's inventory or health). One good approach is to use the Dialogue System's Lua environment and the OnConversationStart/OnConversationEnd messages:

Message Task
OnConversationStart Record your gameplay data into the Lua environment so your conversation can access and/or manipulate it
OnConversationEnd Apply any changes from the Lua environment into your gameplay data

The FPSyncLuaPlayerOnConversation.cs script demonstrates how this is done in VisionPunk's UFPS. It uses the DialogueLua class to store and retrieve UFPS data in the Lua environment.


Gameplay Integration in the Feature Demo

The Feature Demo can give you an overview of how to integrate the Dialogue System with your own gameplay components.

In the Feature Demo example scene, the Player object has a Set Enabled On Dialogue Event component that disables these gameplay components on conversation start:

The same component also re-enables them on conversation end.

In addition, the first dialogue entry in Private Hart's conversation uses the LookAt() sequence command to make the player and Hart look at each other.


<< Save System | Scripting >>