Interacting with NPCs in Narrative Pro

- by

To interact with a Non-Player Character in Narrative Pro, we need to first

  • create an NPC Definition
  • spawn them into the world
  • create a dialogue
  • and attach it to the NPC definition

In addition we’ll see how to bring up a dialogue option only if the player has an item in their inventory, and how we can give it to the NPC. Let’s take a look how all this works.

Creating and spawning an NPC

Create an NPC Definition by right-clicking in the content browser (under Narrative – Characters section).

All we need for now is an appearance, a name and a pre-filled GUID. To bring our NPC into the world, we can use an NPC Spawner object, which in turn lets us use a utility function to spawn the NPC itself (it’ll dock itself as NPCSpawn in the object’s hierarchy).

Select the NPC and pick the definition we’ve setup earlier (I’ve called mine The Professor).

Now when we start the game, we’ll see our NPC in the world. Sadly we can’t yet interact with him, but we’ll fix that in the next step.

Creating the Dialogue

Narrative has a seriously rad node-based tool to layout the flow of the dialogue. They can be expanded with logic, group chats and quests, but we won’t worry about the complex stuff for now. Let’s just get our NPC talking. Right-click in the content browser, and in the Narrative section, create a Dialogue asset.

With Class Defaults selected, we can tell our dialogue which speakers will participate. I’ll choose my NPC, then drag off the initial grey node, and select my NPC to create my first speaker node. I’ll leave it empty and create a second node, pick my NPC again and enter some text for him to say. Next I’ll create a branching network of dialogue options, each of which will appear for my player to select. It’s super fast and easy.

To make this play out, all we have to do is to add the dialogue asset to the NPC definition and it will become an interactable character as if by magic. Previously selected options are remembered and automatically greyed out. How cool is that?

Testing for Inventory Items

A common thing in dialogues is to check if the player has an item. If so, an additional dialogue option comes up, perhaps as part of a quest. In Narrative Pro we can use a dialogue condition to check for this.

On my player response, I can add a condition that tests the player’s inventory for a specific item, and only if the player has it will this option show as selectable.

Removing an inventory item via dialogue

Let’s assume the task is for me to give the item we’ve tested for to the NPC. This can be done by double-clicking on a dialogue node, whereupon a custom event shows that fires on the node. In my case, the professor wants a Mammoth bone that happened to lie around in the level. Lucky me!

Here I grab the player controller, from which I extract the inventory component. The Remove Item function requires an “item” not a class, so I’ll find all items from the “Mammoth bone” class. This returns an array from which I grab the first item, which is then duly removed from the player’s inventory.

There’s a lot more to explore in dialogues like camera shots, face and body animations, alternate random lines, player positions, multiple speakers and Quests integration.



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment