This feature is in an experimental state so you can try it out, provide feedback, and see what we are planning. You cannot publish a project that uses persona or its related features at this time.
To use this feature, you need to enable the persona_component in the Experimental Scene Graph features. Then, under Experimental Access, check Runtime AI.
Prerequisites
Now that you have created your first persona and refined its personality and knowledge through interacting with it in the Prompt Editor, you can add your NPC to a conversation. To converse with an NPC in game, you must:
Define a new
npc_behaviorin Verse.Add your
npc_behaviorto your NPC Character Definition.Add your NPC Character Definition to an NPC Spawner.
Ensure you have Voice Chat Enabled as Voice Chat is required to converse with persona NPCs.
Create an Empty NPC Behavior
To set up a custom NPC Behavior in Verse, follow these steps:
In the Menu Bar, select Verse > Verse Explorer.
In the Verse Explorer, right-click on your project name and choose Add new Verse file to project to open the Create Verse Script window.
In the Create Verse Script window, click NPC Behavior Basic to select it as your template.
Name the NPC Behavior persona_npc_behavior under Configure.
Select Create to create your Verse file.
If you select NPC Behavior instead of NPC Behavior Basic and choose Create for your persona_npc_behavior, the created Verse file contains a predefined npc_behavior with existing functionality that you must replace with behaviors explained here. This tutorial provides you with a full npc_behavior Verse script you can use, so you are safe to choose NPC Behavior Basic with Create or Create Empty since the script provides everything you need.
The persona_npc_behavior is where you can define and add a persona_component to your NPC through Verse. All NPCs spawned by NPC Spawners are agents and have an associated entity. This associated entity is how you add Scene Graph Components, such as the persona_component to an NPC agent.
The persona_component is added automatically when a Persona Modifier is added to an NPC.
NPC Behaviors are defined in Verse inheriting from the base npc_behavior class. For more information about NPC Behaviors, see the Understanding NPC Behaviors page.
Edit your Persona NPC Behavior
Verse is required to add your NPC persona as a conversation target for the player. Without adding your NPC as a conversation target for your player, you cannot converse with your NPC persona.
Below is a Verse script defining the persona_npc_behavior in the section persona_npc_behavior.verse. To add this Verse code to your empty persona_npc_behavior, follow these steps:
In the Menu Bar, select Verse > Open Project in VS Code…
Once VS Code opens, find your
persona_npc_behavior.versefile in the VS Code Explorer.Copy and paste the content of
persona_npc_behavior.versebelow into your Verse file in your project.Compile your Verse code either in the UEFN Toolbar or within VS Code.
For a step-by-step walkthrough of the Verse script, follow the steps under Explanation of Script.
persona_npc_behavior.verse
using { /Fortnite.com/AI }
using { /Fortnite.com/Playspaces }
using { /UnrealEngine.com/Conversations }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Chat }
using { /Verse.org/SceneGraph }
using { /Verse.org/Simulation }
Explanation of Script
Import the necessary modules.
Verseusing { /Fortnite.com/AI } using { /Fortnite.com/Devices } using { /Fortnite.com/Playspaces } using { /UnrealEngine.com/Conversations } using { /UnrealEngine.com/Temporary/Diagnostics } using { /Verse.org/Chat } using { /Verse.org/SceneGraph } using { /Verse.org/Simulation }Create a log channel. This is a good practice for logging. See Debugging and Troubleshooting in Verse for more information on logging.
Versepersona_log := class(log_channel){}Add a logger to log any relevant messages to report errors, warnings, and important debug messages.
Versepersona_npc_behavior := class(npc_behavior): Logger:log = log{Channel := persona_log}To ensure that your player can converse with your NPC as soon as play begins, you need to add the NPC as a conversation for your player. Define a new
AddPlayerAsConversationTargetfunction. To add an NPC as a conversation target for a player, the NPC persona must belong to a team that the player belongs to and be added to a voice chat channel that the player belongs to. The simulation entity contains information about available voice channels.Versepersona_npc_behavior := class(npc_behavior): # Fields # ... # Functions # Add the Player as a conversation target for this NPC AddPlayerAsConversationTarget(Player:player):void= if:Once play ends, NPCs should be cleared out as potential conversational targets for players. Define a new
RemovePlayerAsConversationTargetfunction.Versepersona_npc_behavior := class(npc_behavior): # Fields # ... # Functions # ... # Remove Player as a conversation target RemovePlayerAsConversationTarget(Player:player):void=Override
OnBeginto automatically add this NPC as a conversation target for players.Versepersona_npc_behavior := class(npc_behavior): # Fields # ... # Functions # ... # NPC Behavior EventsLastly, override
OnEndto remove this NPC as a conversation target for players.Versepersona_npc_behavior := class(npc_behavior): # Fields # ... # Functions # ... # NPC Behavior Events # ...
Add NPC Behavior to NPC Character Definition
To add your persona_npc_behavior to your NPC Character Definition, follow these steps:
Navigate to your PersonaNPCDefinition in the Content Drawer.
Select the PersonaNPCDefinition to open for editing.
Under NPC Character Behavior, select Verse Behavior > persona_npc_behavior.
Ensure you save your changes to your NPC Character Definition before closing the tab.
Once your NPC Character Definition is added to an NPC Spawner, your NPC persona is automatically added as a conversation target for your player.
Add NPC Spawner with NPC Character Definition
To spawn an NPC with your customized persona, you must add an NPC Spawner to your level and add your PersonaNPCDefinition. To add an NPC Spawner Device, drag your PersonaNPCDefinition from the Content Drawer into the Viewport.
Converse with your NPC
To converse with your NPC, launch a session and start the game. Press the key or button on your input device indicated on-screen and converse with your NPC!