Compelling virtual characters are crucial for immersive gaming experiences. They bring the game world to life, provide context, and engage players in meaningful interactions.
However, traditional scripted character conversations often feel rigid and repetitive and fail to adapt to player choices, which breaks immersion.
Imagine a virtual world where characters react dynamically, hold meaningful conversations, and adapt their behaviors based on player choices. That's where artificial intelligence (AI)-powered narrative design comes in. AI-driven systems enable dynamic, contextually relevant dialogues that adapt to player actions, maintaining the narrative's flow and coherence.
Convai's platform lets game developers make AI-powered virtual characters with deep personalities and storylines with which they can interact. These virtual AI characters can be integrated into platforms like Unreal Engine, Unity, PlayCanvas, and more!
In this technical guide, we'll explore how Convai's narrative design feature allows developers to craft compelling character interactions in platforms like Unreal Engine and Unity—whether they're indie developers or part of a large studio.
You’ll learn the technical aspects of integrating AI-driven dialogues, creating branching narratives, and optimizing performance for seamless gameplay experiences.
Traditional Approaches to Character Dialogue and Behavior
In traditional game development, character interactions and behaviors have been implemented using scripted dialogue trees and finite state machines. While these approaches have been widely used, they have several limitations that can impact the player experience.
- Scripted dialogue trees are pre-written conversations where the player chooses from predefined responses that lead to branching paths in the conversation. This approach allows for structured interactions but lacks the flexibility to handle dynamic or unexpected player input.
- Finite state machines (FSMs) model a character’s behavior by defining a set of states and their transitions based on specific conditions or player actions. FSMs provide a clear structure for character behavior but can become complex and difficult to manage as the number of states and transitions grows.
The limitations of these traditional approaches include:
- Linear, pre-defined interactions: Scripted dialogues and FSMs often result in linear, predefined interactions that feel rigid and cannot adapt to the player's choices or actions in real-time.
- Lack of dynamic, contextual responses: Traditional systems struggle to generate dynamic, contextually relevant responses to player input, as they rely on predefined dialogue options and state transitions.
Repetitive, robotic NPC behavior: Due to their limited flexibility and lack of dynamic adaptation, virtual characters can exhibit repetitive and robotic behavior, undermining the game's immersion and believability.
These limitations have driven the need for more advanced techniques, such as AI-driven narrative design, to create engaging, dynamic, and responsive character interactions that improve the player experience.
Artificial Intelligence (AI)-Driven Narrative Design
Narrative design in video games is changing because AI allows players to interact with non-playable characters in interesting and dynamic ways. Breakthroughs in foundation models have allowed character-based conversational AI to have human-like capabilities and behaviors.
AI improves characters' dialogue in several important ways:
- Generating contextually relevant responses: AI-powered characters can analyze the context of a conversation and generate appropriate responses that feel natural and coherent. By understanding the topic, tone, and intent of the player's dialogue, AI can craft replies that fit the flow of the conversation.
- Adapting to player choices and actions: AI allows characters to react dynamically to the player's decisions and behavior. Whether the player chooses to be friendly, hostile, or neutral, the characters can adjust their dialogue accordingly to generate a more immersive and responsive experience.
Maintaining character personality and goals: With AI, characters can exhibit consistent personalities, motivations, and goals throughout the game. By adhering to predefined traits and objectives, AI ensures that character dialogue remains true to their character, even as they adapt to different situations.
In addition to enhancing dialogue, AI enables dynamic character behavior that brings the game world to life:
- Reacting to game-world events: AI-controlled characters can perceive and respond to events around them, such as changes in the environment, the presence of other characters, or player actions. This responsiveness creates a sense of realism and immersion.
- Pursuing goals and making decisions: AI allows characters to have their agendas and make autonomous decisions based on their goals, preferences, and the state of the game world. When pursuing objectives, the character acts more like living and thinking things.
Interacting with the environment and other characters: AI enables characters to navigate the game world, manipulate objects, and engage in meaningful interactions. These behaviors contribute to the believability and depth of the game's narrative.
👀 See Also: The Future of Gaming: How AI Characters Enhance the Player Experience.
Convai's Narrative Design Feature
Convai's narrative design feature empowers game developers to create dynamic, engaging AI-driven character interactions. It enables developers to define high-level objectives and decision points for characters, guiding the flow of conversations while maintaining the flexibility and responsiveness of AI-generated dialogues.
Under the hood, the narrative design uses advanced language models (LLMs) to power character conversations. Narrative graphs can outline character objectives, decisions, and triggers within a structured framework. This approach allows you to steer the direction of character interactions while preserving the open-ended nature of AI-driven dialogue.
You can get started with narrative design at the Convai Playground and creating your own Convai account.
Firstly, select the character you want to enable narrative design:
Select the Narrative Design option from the side panel and create your narrative design flow:
The detailed playlist here outlines creating a narrative design graph for your virtual world stories in the Convai Playground, and also shows end-to-end the process of bringing an AI character to Unity’s factory scene.
Here is an example of a WIP narrative design:
You can also extend narrative design from the Playground to Unreal Engine and Unity projects.
You can invoke triggers created with the narrative graph and access dynamic variables such as the time of day or relevant information like inventory contents in the game.
Let’s see how you can accomplish this in the following sections.
Implementing AI Narrative Design in Unity with Convai
Step 1: Add the Narrative Design Manager Component
1. Select your Convai Character in the scene and look for ConvaiNPC component in the inspector panel. Click on the Add Components button:
2. Select Narrative Design Manager checkbox, and then click on the Apply Changes button:
Step 2: Setup the Narrative Design Component
After adding the Narrative Design Component, you will be able to add the following component:
This component system assumes that the API key is set up correctly, so ensure that it is set up correctly; otherwise, an error will be thrown.
After adding them, the component will retrieve the sections for the character ID taken from the ConvaiNPC. Please wait for some time, depending on your network speed.
Step 3: Add Section Triggers
Select the game object you want to trigger; we have selected a simple cube in this example, but it's up to your imagination. Ensure that the game object you have decided to be a trigger has a collider attached.
Add Narrative design Trigger from Add Component menu by searching for it:
Make the Collider a trigger:
Assign your Convai character to the Convai NPC field:
Now you can select from the "Trigger" dropdown which trigger should be invoked when a player enters this trigger box.
We have also added a way for you to invoke this trigger manually. You can use InvokeSelectedTrigger function to invoke the trigger from anywhere.
Now that you have the narrative design, learn to set up an NPC-to-NPC conversation within Unity using the Convai SDK.
Implementing AI Narrative Design in Unreal Engine with Convai
You can dynamically pass variables to the narrative design section and triggers used with Unreal Engine blueprints.
We will create a simple scenario where the character welcomes the player and asks them about their evening or morning based on the player's time of day.
New to Unreal Engine (UE) characters? See how to integrate AI characters with MetaHuman Avatars in UE 5 in this video:
Step 1: In the playground, enable Narrative Design on your character and change the starting section name to Welcome.
Step 2: Add the following to the Objective field of the Welcome section:
"The time of day currently is {TimeOfDay}. Welcome the player and ask him how his {TimeOfDay} is going."
Notice that adding any string between curly brackets becomes a variable. Here, you added the “time of day” as a variable. Then, from Unreal, we can pass either the word "Morning" or "Evening," and the character will respond accordingly.
Ensure the variable names are between curly brackets and have no spaces in between.
Step 3: Back in Unreal, open the character's blueprint.
Step 4: Set the Narrative Template Keys variable with a map containing the same variable name, TimeOfDay. For demonstration purposes, you will hard code the value to "Morning."
Step 5: Start the play mode and try it out.
Nice! Feel free to try other scenarios and settings that better align with your use case. You can use the narrative design keys feature in both sections and triggers. You can also dynamically set, change, or clear the narrative keys in Unreal blueprints.
⚡See Also: How to Extend Narrative Design Triggers with Unreal Engine.
Best Practices and Considerations for AI-Driven Narrative Design
Craft Compelling Character Arcs and Development
To create memorable characters, focus on developing well-rounded characters with distinct personalities, motivations, and backstories. Give them flaws, strengths, and desires that drive their actions and dialogue.
Consider how their experiences and interactions with the player shape their growth and evolution throughout the game.
Balance Player Agency and Narrative Structure
While AI powers characters to respond dynamically, it's crucial to maintain a cohesive narrative structure. Strike a balance between player agency (allowing choices that impact the story) and guiding the player through key plot points.
Use Convai's conditional branches to adapt the narrative flow based on player decisions while ensuring the story progresses meaningfully.
📰 Recommended: Integrate Dynamic NPC Actions in Game Development with Convai
Handle Edge Cases and Unexpected Player Actions
The character may encounter situations lacking context for what to do. Anticipate and prepare for edge cases where player input might deviate from expected responses. Use Convai's Knowledge Bank feature to create fallback responses or redirect the conversation to maintain narrative coherence.
Playtest and Iterate on AI-Driven Narratives
Thorough playtesting is essential for refining AI-driven narratives. Gather feedback from playtesters to identify areas where dialogue feels unnatural, storylines become confusing, or player choices lead to unintended consequences.
Based on this feedback, iterate on your narrative graphs, dialogue options, and character configurations.
📰 Recommended: Experience Safety Overview: Understanding Guardrails for Convai-Powered AI Characters.
Optimize Performance for Real-Time Character Interactions
Optimize your AI-driven narratives to ensure smooth and responsive interactions, especially in large-scale games or virtual worlds.
Consider techniques such as caching frequently used responses, preloading assets for upcoming dialogues, and optimizing the frequency of API calls to Convai's servers.
Conclusion - Bringing NPCs to Life: AI-Driven Narrative Design in Unreal Engine and Unity
Convai's Narrative Design feature helps developers craft dynamic character interactions and immersive storytelling experiences. Developers can create characters with Convai’s platform, which responds to player choices powered by AI and LLMs.
This can provide characters with consistent personalities and direct conversations toward important narrative objectives. With its sections, decisions, and triggers, the Narrative Graph framework lets game developers balance authored content with emergent interactions.
This method ensures the story makes sense while letting players shape their stories through natural conversations and choices with real-world effects.
Convai's platform offers developers the tools and flexibility to push the boundaries of interactive storytelling, crafting games where every interaction feels alive and every choice matters.
With Convai's documentation and community, you'll be well on your way to creating AI characters that will captivate your users and bring your virtual world to life like never before.
Also, subscribe to this YouTube channel and stay updated with our latest developments.
Write to us at support@convai.com for collabs or business-related engagement.