Invector Third Person Controller Support

This page describes how to set up the Dialogue System with Invector's Third Person Controller. (Invector's Third Person Controller is required.)

Third Person Controller copyright © Invector.

Setup

This integration correctly pauses the Invector character during conversations.

To set up your character:

  1. If you are using the paid version of Invector, import the package Plugins ► Pixel Crushers ► Common ► Third Party Support ► Invector Support. This will unpack files into the folder Assets ► Pixel Crushers ► Common ► Third Party Support ► Invector Support.
  2. Otherwise, if you are using the free version of Invector, add the scripting define symbol USE_INVECTOR_FREE to Edit → Project Settings → Player → Other Settings → Scripting Define Symbols.
  3. Import the package Plugins ► Pixel Crushers ► Dialogue System ► Third Party Support ► Invector Support. This will unpack files into the folder Assets ► Pixel Crushers ► Dialogue System ► Third Party Support ► Invector Support.
  4. Add a Dialogue Manager GameObject by adding the prefab in Prefabs.
    • Untick the Input Device Manager's Control Cursor State checkbox to allow Invector to control the cursor state.
  5. Inspect the Invector character.
    • Add a Dialogue System Invector Bridge component.
    • If you want to use the Dialogue System's interaction system, add a Selector or Proximity Selector.
      • Also add a Dialogue System Events component to disable the Selector / Proximity Selector during conversations.
      • You can also configure the Dialogue System Events component to hide Invector's UI during conversations.
    • To include your character in the Save System, add InvectorStatsSaver and/or InvectorInventorySaver components (see Saving, Loading, & Scene Changes).
  6. When configuring a Dialogue System Trigger on an NPC to run a conversation, if you want to show the mouse cursor tick the Show Cursor During Conversations.

To set up interactable NPCs:

See Private Hart in the example scene for an example of how to set up an NPC to start a conversation using Invector's interaction system. It was set up using these steps:

  1. Add a trigger collider, vTriggerGenericAction, and Dialogue System Trigger.
    ![](images/thirdParty/invector/invectorInteraction1.png)
  2. Add a vActionText child GameObject. Set it inactive. This GameObject will show the interaction prompt when the player enters the trigger collider.
  1. Configure the vTriggerGenericAction's OnPlayerEnter() and OnPlayerExit() events to activate and deactivate vActionText, respectively.
  1. Configure the vTriggerGenericAction's OnPressActionInput() event to call the DialogueSystemTrigger's OnUse method and deactivate vActionText.
  1. Configure the DialogueSystemTrigger to start a conversation.

Under some Invector configurations, it's possible that Invector will change the collider at runtime, causing the character to fall through the floor. In this case, add the components above to an empty child GameObject instead.

If Invector's interaction system doesn't show the vActionText when you approach the NPC, make sure the NPC has a trigger collider and that the GameObject is on a layer that the player's collider will detect.

On your player, remember to add a Dialogue System Invector Bridge component as described in the Setup section above.

Example Scene

The example scene demonstrates how to interact with an NPC and start a conversation.

Lua Functions

The Dialogue System Invector Bridge component adds these Lua functions, which operate on the player:

Lua Function Description
vGetHealth() Returns the player's current health.
vGetMaxHealth() Returns the player's max health.
vAddHealth(amount:int) Increases the player's current health.
vAddMaxHealth(amount:int) Increases the player's max health.
vAddItemByID(itemID:int, amount:int, autoEquip:bool) Gives items to the player. (See below.)
vRemoveItemByID(itemID:int, amount:int) Removes items from the player. (See below.)
vGetItemCount(itemID:int) Returns the amount of an item the player has. (See below.)

In the '...' Lua wizard dropdowns, these functions are available in Custom > Invector.

Inventory Management

Some Invector controllers feature an inventory system. If you want to give items to the player during a conversation, add the scripting define symbol USE_INVECTOR_INVENTORY to Edit → Project Settings → Player → Other Settings → Scripting Define Symbols. This will add the following Lua functions:

vAddItemByID( itemID:int, amount:int, autoEquip:bool )

vRemoveItemByID( itemID:int, amount:int )

vGetItemCount( itemID:int ) ​ (Note the 'v' at the front of the function names.) You can use vAddItemByID and vRemoveItemByID in your conversations' Script fields, such as:

vAddItemByID(3, 1, true)​

If you're using Invector's example items, 3 is the ID for the sword. So the command above adds 1 sword to the player and auto-equips it.

You can use vGetItemCount in your conversations' Conditions fields, and in Dialogue System Trigger Conditions, to check how many of an item the player has.

Saving, Loading, & Scene Changes

If you will use the Dialogue System's Save System to save and load games or change scenes (e.g., using the LoadLevel() sequencer command), untick your character's Use Instance checkbox. Otherwise you will get duplicates of your character.

Note: Some versions of Invector controllers do not have a Use Instance checkbox.

Also locate the inventory UI prefab that your character will use (e.g., Inventory_ShooterMelee) and untick its Don't Destroy On Load checkbox.

To save a character's current and max health, add an Invector Stats Saver component.

To save a character's inventory, add an Invector Inventory Saver component. Requires the USE_INVECTOR_INVENTORY scripting define symbol to be set. This saver is a work in progress. It saves and restores the character's inventory but doesn't yet restore items to their original equip areas.

If you add both saver components, assign unique keys to each one.

Respawning and Reloading Saved Games

To handle respawning, add a script similar to the one below to the player GameObject. It replaces Invector's default respawn functionality with one that reloads from a saved game. If there is no saved game, it can do something else such as show a UI load game panel or return to the main menu. (See the comment at the bottom of the script.)

ReloadWhenDead.cs

using System.Collections;
using UnityEngine;
using Invector.vCharacterController;
public class ReloadWhenDead : MonoBehaviour
{
public int checkpointSaveSlot = 0;
private IEnumerator Start()
{
// Wait for player to initialize:
var framesToWait = SaveSystem.framesToWaitBeforeApplyData + 1;
for (int i = 0; i < framesToWait; i++)
{
yield return null;
}
var controller = GetComponent<vThirdPersonController>();
// Then unhook Invector's regular death event and replace it with our own:
controller.onDead.RemoveAllListeners();
controller.onDead.AddListener(ReloadOnDeath);
}
private void ReloadOnDeath(GameObject player)
{
if (SaveSystem.HasSavedGameInSlot(checkpointSaveSlot))
{
SaveSystem.LoadFromSlot(checkpointSaveSlot);
}
else
{
// Show load game menu? Go to main menu? etc. (Add your code)
}
}
}
This is the main Save System class.
Definition SaveSystem.cs:17
static void LoadFromSlot(int slotNumber)
Loads a game from a slot.
Definition SaveSystem.cs:798
static bool HasSavedGameInSlot(int slotNumber)
Returns true if there is a saved game in the specified slot.
Definition SaveSystem.cs:744
static int framesToWaitBeforeApplyData
When loading a game/scene, wait this many frames before applying saved data to allow other scripts to...
Definition SaveSystem.cs:151
Definition MessageEventsEditor.cs:7

<< Third Party Integration