Neocortex Logo
Add an AI character to your Unity game step by step: install the Neocortex SDK, drop in a voiced character, then wire its replies, emotions and actions.

How to Add an AI Character to Your Unity Game

TutorialUnityAI NPC

Most guides for AI characters in Unity stop at a chat box. This one goes from an empty scene to a voiced character who answers the player, shows emotion and triggers gameplay, using the Neocortex Unity SDK. It takes about fifteen minutes, and the first conversation needs no code at all.

What you'll build

Brannoch, a village blacksmith players can talk to by typing or speaking. He answers in his own voice, his mood shows on every line, and he can hand over an item when the conversation earns it.

What you need

  • Unity 6 (6000.0) or later
  • Git installed, since the SDK installs from a git URL
  • A free Neocortex account

Step 1: design the character

In the Neocortex dashboard, create a character and fill in the editor: a personality with what Brannoch wants and how he talks, a knowledge base with your village's lore, a voice, and an Action node called GIVE_ITEM with a short note on when to use it. Talk to him in the browser until he sounds right. In-editor testing is free on every plan. Our guide on how to give NPCs unique personalities covers what to write.

Step 2: install the Neocortex Unity SDK

In Unity, open Window > Package Manager, click +, choose Add package from git URL and paste:

https://github.com/neocortex-link/neocortex-unity-sdk.git

Step 3: add your API key

The settings window opens by itself the first time. If it doesn't, open Tools > Neocortex > Settings, paste the API key from your dashboard and press Save. The same window lists your characters and your plan.

Step 4: add the character to your scene

Right-click in the Hierarchy and choose Neocortex > Complete Voice Chat. This creates a "Neocortex Character" GameObject with everything a voiced character needs, plus a canvas with a chat panel, a thinking indicator and a microphone button:

  • Neocortex Smart Agent: the character itself. Pick Brannoch from its character dropdown.
  • Audio Source: where his voice plays.
  • Neocortex Audio Receiver: the microphone, listening with voice detection by default.
  • Neocortex Chat UI: connects the agent to the chat panel and the microphone button.

Prefer typing? Neocortex > Complete Text Chat builds the same rig with a text box instead of the microphone, and replies as text.

Step 5: press Play and talk

Press Play and say hello. Brannoch answers out loud in his own voice, and the chat panel shows both sides of the conversation. You now have a working AI character in Unity without a line of code.

Step 6: connect the character to your game

A character becomes part of the game when its replies drive animation and gameplay. The Smart Agent raises a Unity event for each part of a reply, and RegisterAction connects actions to your own code:

using System.Collections;
using UnityEngine;
using Neocortex;
using Neocortex.Data;

public class Blacksmith : MonoBehaviour
{
    [SerializeField] private NeocortexSmartAgent agent;
    [SerializeField] private Animator animator;

    private void Start()
    {
        agent.OnChatLineStarted.AddListener(line => Debug.Log(line.text));
        agent.OnEmotionChanged.AddListener(emotion => animator.SetTrigger(emotion.ToString()));
        agent.OnRequestFailed.AddListener(error => Debug.LogWarning(error));
        agent.RegisterAction("GIVE_ITEM", GiveItem); // authored on the character's Action node
    }

    private IEnumerator GiveItem(ChatAction action)
    {
        if (PlayerHasPaid()) Inventory.Give(action.targetId); // your own game code
        yield return new WaitForSeconds(0.5f); // the next action waits for this one
    }
}

PlayerHasPaid and Inventory stand in for your own systems. The character asks for the action, and your code decides whether it happens.

A few settings on the Smart Agent are worth knowing:

  • Chat Lines Mode: PerLineAudio voices each line as it comes, SingleAudio voices the reply as one clip, Text shows lines without voice, and Off hands you the raw reply to present yourself.
  • Action Trigger: run actions when the reply arrives, when speech starts, or after the line is spoken.
  • Load History On Start: shows the last conversation when the scene opens.

Let the character see the scene

Add a Neocortex Interactable component to objects the character should know about: the anvil, the gate, the sword on the wall. Each one needs a collider, gets a stable id, and can carry properties such as state: closed. The SDK sends the nearest interactables with every message, so Brannoch can say "the sword on the wall isn't for sale" and point an action at its id. Our guide on how to make AI NPCs act on what they say covers the design side.

The sample scenes

The SDK ships six samples in the Package Manager's Samples tab: text chat, audio chat, actions, interactables, group chat, and usage gating. Group chat puts up to six characters in one conversation and needs the Pro or Team plan.

Common problems

  • "API Key is required." The key isn't saved. Open Tools > Neocortex > Settings and press Save.
  • No voice in a WebGL build. Unity's microphone doesn't work in browsers. Select the Neocortex WebGL template in Player Settings, and host the build over HTTPS. Our Unity voice chat guide has the details.
  • The player speaks while the character is talking. The agent queues the new message and sends it when the reply ends, so nothing gets lost.
  • Your key ships with the build. Create a separate API key for each release, set per-player and per-character usage limits on it, and deactivate it from the dashboard if it leaks. The usage gating sample shows how to check limits in game.

Next steps

  • Add voice input and lip sync: how to add voice chat to AI NPCs in Unity
  • Voice your scripted lines in the same voice: text-to-speech for NPC dialogue in Unity
  • Building for a headset: AI characters in a Meta Quest game
  • Wondering how this compares with calling an LLM yourself: how to make NPCs talk with ChatGPT in Unity

Every tutorial in the series is in the guide to building AI NPCs, and the Unity integration page has the requirements in one place.

Frequently Asked Questions

How do I add an AI character to my Unity game?

Design the character in the Neocortex editor, install the Neocortex Unity SDK from its git URL, paste your API key in Tools > Neocortex > Settings, then add a Neocortex Smart Agent to a GameObject and pick the character. Press Play and talk to it by text or voice.

Which Unity versions does the Neocortex SDK support?

Unity 6 (6000.0) or later, on Windows, macOS, Android, iOS and WebGL.

Can a Unity AI NPC trigger gameplay?

Yes. Define actions on the character in the Neocortex editor, then register a coroutine for each one with RegisterAction. Each action arrives with the id of the object it targets, and your code decides whether to run it.

Is my API key safe in a Unity build?

Any key inside a build can be extracted, so plan for it. Neocortex API keys can carry usage limits per player and per character, checked on our servers before every request, and you can deactivate a key from the dashboard.

Is it free to add an AI character to Unity?

You can build and test on the free plan, which includes free in-editor testing. Commercial games need the Pro or Team plan.

Written by

Neocortex

Date

Nov 3, 2026

Updated

Nov 3, 2026

Read time

9 min

Read More