Opsive UFPS v1 Support

This page describes how to set up the Dialogue System with Opsive's UFPS version 1. (UFPS is required.)

For instructions on current Opsive Character Controller integration, see Opsive Character Controllers Support.

UFPS copyright © Opsive.

UFPS Setup

This package adds functionality to:

  • Start conversations using UFPS's interaction framework.
  • Suspend UFPS gameplay during conversations.
  • Synchronize UFPS data between UFPS and the Dialogue System.
  • And load and save games containing UFPS and Dialogue System data.

Follow these steps to set up the Dialogue System with UFPS.

Import The UFPS Support Package

Contact Pixel Crushers for the integration package. It's no longer included with the Dialogue System package itself.

If you want to use the Dialogue System Menu Framework with UFPS, see Set Up the Dialogue System Menu Framework.

For instructions on current Opsive Character Controller integration, see Opsive Character Controllers Support.

Example Scene

Play the example scene to see how the Dialogue System works with UFPS.

In this example:

  • The player is configured for full UFPS/Dialogue System integration. (See Set Up The Player)
  • Private Hart is configured as an NPC with a conversation and a quest. (See Set Up NPCs)
  • There is a destructible crate. (See Set Up Destructibles)
  • There is full save and load functionality.

Set Up The Dialogue Manager

Set up the Dialogue Manager GameObject normally as described in Dialogue Manager. Then add these components:

  • Level Manager: This component handles general synchronization of levels and Dialogue System data when changing levels and loading games.
  • FP Sync Lua Player On Load Level: (Component → Pixel Crushers → Dialogue System → Third Party → UFPS → Sync Lua Player On Load Level) This component applies the Dialogue System's Lua data to the UFPS player GameObject after loading a level.

The FPSync Lua Player On Load Level component allows you to have a different UFPS player GameObject in each level so you can test a level simply by playing it in the editor. When playing a game, before changing levels you can save the player's current UFPS data, such as health and inventory, into the Dialogue System's Lua environment. When the new level is loaded, this component applies the saved data from the previous level to the player GameObject in the new level.

Set Up The Player

Automatic Player Setup

To set up the UFPS player in your scene, first make sure it has a UFPS player such as Camera&Controller, AdvancedPlayer, or HeroHDWeapons. Then select menu item Tools → Pixel Crushers → Dialogue System → Third Party → UFPS → Add All Player Scripts. This will automatically configure your player with these scripts:

  • FP Player Lua Bridge: Syncs data between UFPS and the Dialogue System.
  • FP Persistent Player Data: Saves & loads the UFPS player state in saved games and across scene changes.
  • FP Freeze Player: Freezes the player and shows the cursor during conversations.

Additional Player Components

vp_FPInteractManager for UFPS Interaction Some UFPS player prefabs, such as Camera&Controller, don't start with a vp_FPInteractManager component. This component is required to use UFPS interaction, such as with FPInteractable Dialogue. If you want to use UFPS interaction, make sure your player has a vp_FPInteractManager.

Players with Bodies

Players with bodies, such as HeroHDWeapons, need an additional component. Add a Dialogue System Events, disable these three components in OnConversationStart, and re-enable them in OnConversationEnd:

  • The body's vp_FPBodyAnimator
  • The body's vpRagdollHandler
  • The FPSCamera's vp_FPCamera

Set Up NPCs

On NPCs, add these components:

  • FP Interactable Dialogue: Derived from vp_Interactable, this component makes the NPC interactable within the UFPS framework. When the player interacts with the NPC, this component sends an OnUse message to the NPC. If the NPC has a Dialogue System Trigger configured to listen for OnUse, it will activate.
  • Dialogue System Trigger: Configure it to do something such as start a conversation OnUse.
  • Dialogue System Events: Add this component and configure it to disable the FP Interactable Dialogue component during conversations.
  • Persistent Position Data: Add this component if you want to record the NPC's position in saved games or when changing levels.

If you want to use the Dialogue System's Selector functionality instead of UFPS's interaction framework, don't add FP Interactable Dialogue, and instead add a Usable component.

You can also set up barks and other Dialogue System features as normal, without having to configure any special UFPS versions.

Set Up Destructibles

On destructible objects such as crates, or killables such as enemies, add this component:

  • Dialogue System On Die: Performs various actions when the GameObject is "killed." The options are:
    • Destroy: Tick if you want to destroy the object instead of just deactivating it.
    • Sequence: An optional cutscene sequence to play. (See Cutscene Sequences) For example, you can use KGFMapIcon() to change icons, Audio() to play audio, etc. The "speaker" is the Dialogue Manager GameObject, and the "listener" is the object that was killed.
    • Lua Code: Any Lua code that you want to run.
    • Variable To Record Death. If specified, this variable records that the GameObject was killed. This allows the GameObject to remember that it was killed when you load a game. You don't have to define this variable ahead of time in the dialogue database. You must provide a unique variable name for each GameObject so the GameObjects know which variable corresponds to which GameObject. Leave blank if you don't want to record death.
    • Variable To Increment: If specified, this variable increments when the GameObject is killed. This is useful for kill quests and collection quests. You don't have to define this variable ahead of time in the dialogue database. Leave blank if you don't want to keep track.

Set Up Level Transitions

To set up a level transition trigger, create a GameObject with a trigger collider. Then add a Dialogue System Trigger set to OnTriggerEnter that runs a Sequence. In the Sequence, use the LoadLevel() sequencer command.

Set Up the Dialogue System Menu Framework

Note: The Dialogue System Menu Framework hasn't been updated for version 2.0 yet.

To use the Dialogue System Menu Framework (available on the Dialogue System extras page at www.pixelcrushers.com/dialogue-system-extras/), follow these steps:

Short Instructions

These instructions will get the Menu Framework running with UFPS with the least work.

  1. Import the Menu Framework.
  2. Add these scenes to your build settings in order:
    • 0: Dialogue System / Third Party Support / UFPS / Example / Menu Framework Example / Start UFPS
    • 1: Dialogue System Extras / Dialogue System Menu Framework / Example / Loading
    • 2: Dialogue System Extras / Dialogue System Menu Framework / Example / Credits
    • 3: Dialogue System / Third Party Support / UFPS / Example / Menu Framework Example / Gameplay UFPS
    • (If you change the order of scenes or rename Gameplay UFPS, update the scene numbers/names on the Menu System's scripts and the Dialogue Manager's Level Manager script.)
  3. Open the Start UFPS scene.
  4. Inspect Menu System. At the bottom of the Input Device Manager component, click the Add Input Definitions button.

Play the Start UFPS scene to test it out. After you've confirmed that it's working, you can assign your own dialogue database, dialogue UI, etc. You can save the Start UFPS scene's Menu System and Dialogue Manager as prefabs and add them to your gameplay scenes for easy playtesting. In your gameplay scenes' copy of the Menu System prefab, deactivate the TitleMenuPanel child GameObject, as was done in Gameplay UFPS. When using the Menu Framework, in your gameplay scenes add the script FPLockCursorOnStart to your player.

Lua Bridge Data

The FPPlayer Lua Bridge component makes the following information available in the Lua environment during conversations:

Lua Description
Actor["Player"].Health The player's current health.
Actor["Player"].TotalSpace The total capacity of the player's inventory. (read-only)
Actor["Player"].UsedSpace The current used space in the player's inventory. (read-only)
Actor["Player"].RemainingSpace The current remaining space in the player's inventory. (read-only)
Actor["Player"].CurrentWeaponIndex The index of the player's currently-equipped weapon.
Variable["Pistol"],
Variable["Revolver"]
, etc.
(For all weapons defined in the player's vp_Inventory. If the value is 0 or nonexistent, the player does not have the item. If the value is 1 or higher, the player has the item, and the number indicates the amount of ammo. If you set a value during a conversation, the change will be reflected in the UFPS player at the end of the conversation.
Variable["Pistol_Units"],
Variable["Revolver_Units"]
, etc.
The amount of ammo loaded into each weapon.
Variable["Bullet"],
Variable["MachinegunBullet"]
, etc.
The amount of ammo held by the player (outside of weapons).

You can predefine these variables in your dialogue database to make it easier to select them from the Lua dropdown wizards. In the screenshot below, some of these variables have already been defined:

General Interaction Guidelines

Sharing Additional Data

You may want to share additional data between UFPS and the Dialogue System. One way to do this is to put that information in the Dialogue System's Lua environment using variables.

For example, NPC conversations can branch based on whom the player has killed, or what UFPS items the player has in his inventory.

Saving and Loading

See the demo menu script (DemoMenu.cs) for a simple example of how to save and load.

Pre-Game Level Selection Scenes

If the first scene of your game does not have a UFPS player object and a Dialogue Manager object, you'll have to take an extra step. This is the process:

Whenever a new level is loaded, the FP Player Lua Bridge applies the Lua data to UFPS data.

  • [New Level Loaded]
    • Lua --> UFPS

When switching between gameplay levels, the FP Player Lua Bridge in the old level saves the UFPS data to Lua. Then the new level applies the Lua data to UFPS.

  • [Old Level]
    • UFPS --> Lua
  • [New Level Loaded]
    • Lua --> UFPS

If your level selection scene does not have an FP Player Lua Bridge, it will not save UFPS-->Lua.

To address this, you'll need to add some starting values to the dialogue database. These Lua environment will be initialized with these values.

On the Actors tab, add a field named "Health" to the Player. Change its Type to Number. Set the Value to the player's starting health (e.g., 42) and the starting weapon index (e.g., 1):

Similarly, set the other Actor and Variable values as described in the Lua Bridge Data table above.

UFPS Mobile-Addon

Support for the UFPS Mobile-Addon is in the package UFPS Mobile Addon Support. When you import this package, it will add an example folder containing a two-level mobile demo.

IMPORTANT: To be able to switch between levels, you must add 'Mobile Level 1' and 'Mobile Level 2' to the build settings. For the example main menu's Restart Game button to work, you must make 'Mobile Level 1' the first scene in the build settings.

The example menu is accessed through the mobile demo's menu. The Dialogue System Menu object (which contains the example menu script) is a child of the Dialogue Manager object.

Follow these steps to set up up the Dialogue System with the UFPS Mobile Addon:

  1. Add an AdvancedPlayerMobile and RootUI to each scene. These objects don't seem to survive across scene loads very well.
  2. Connect the AdvancedPlayerMobile's vp_SimpleHUDMobile fields to the RootUI as shown here:
  3. Add these components to AdvancedPlayerMobile:
    • FPFreezePlayer
    • FPPlayerLuaBridge
      • Add all usable item types to the Usable Item Types list.
    • FPSyncLuaPlayerOnConversation
    • FPPersistentPlayerData (if you want to save the player's position)
  4. Add these components to the Dialogue Manager:
    • FPSyncPlayerOnLoadLevel

The FPPersistentPlayerData and FPSyncPlayerOnLoadLevel components are only necessary if your player will be switching levels or saving and loading games.

If you're using the Dialogue System's Menu Framework, add this script (ConnectPauseMenu.cs) to the RootUI GameObject, create a menu button, and configure it to call the script's OpenPausePanel method and the RootUI menu's Toggle method.

using UnityEngine;
namespace PixelCrushers.DialogueSystem.UFPS
{
public class ConnectPauseMenu : MonoBehaviour
{
public void OpenPausePanel()
{
var pause = FindObjectOfType<MenuSystem.Pause>();
if (pause == null)
{
Debug.LogError("Can't find Menu Framework PausePanel to open it.");
return;
}
pause.pausePanel.Open();
}
}
}

<< Third Party Integration