A polished demo showing AI-powered NPCs in Unity 2022.3+ using the AINPCEngine SDK. Walk around a medieval village square and have natural conversations with 3 intelligent NPCs who remember you, trade goods, and offer quests.
- Procedural 3D village — scene builds at runtime from primitives (no imported assets needed)
- 3 AI NPCs with distinct personalities:
- Elara (Merchant, gold) — shrewd trader, haggle for potions and weapons
- Theron (Guard, blue) — stoic veteran, suspicious of strangers
- Old Miriam (Quest Giver, green) — cryptic seer, speaks in riddles
- Natural language dialogue — say anything, NPCs respond intelligently
- Persistent memory — NPCs remember your conversations
- Dynamic emotions — glowing emotion orbs above NPCs change color in real-time
- Trade & quest systems — context-aware buttons for each NPC type
- Typewriter text effect — dialogue reveals character by character
- Unity 2022.3 LTS or later
- Docker & Docker Compose
- An AINPCEngine API key (get one at ainpcengine.com)
git clone https://github.com/jyswee/AINPCEngine.git
cd AINPCEngine
docker compose up -dgit clone https://github.com/jyswee/ainpc-unity-demo.gitEdit Assets/Scripts/Config/DemoConfig.cs and set your API key:
public const string API_URL = "http://localhost:16745"; // Default docker-compose port
public const string API_KEY = "dev-api-key-change-me"; // Default dev key
public const string GAME_ID = "ainpc-unity-demo";Note: The default
docker-compose.ymlexposes port 16745. If you deployed via Portainer, the port is typically 18542.
- Open Unity Hub and add this project
- Open with Unity 2022.3+
- The scene builds itself procedurally — just press Play
- Walk with WASD, look with mouse
- Approach an NPC and press E to interact
- Type your message and press Enter or click Send
- Press Escape to close dialogue
ainpc-unity-demo/
├── Assets/
│ ├── Plugins/AINPCEngine/ # AINPCEngine SDK (REST + WebSocket)
│ │ ├── AINPCEngine.cs
│ │ ├── Models.cs
│ │ └── NPCWebSocket.cs
│ └── Scripts/
│ ├── Config/DemoConfig.cs # API configuration (edit this)
│ ├── Setup/SceneBootstrap.cs # Procedural scene builder
│ ├── Managers/GameManager.cs # Singleton: API client & NPC registry
│ ├── Player/PlayerController.cs # WASD movement, mouse look, interact
│ ├── NPC/
│ │ ├── NPCBehaviour.cs # NPC personality, emotions, API registration
│ │ ├── NPCTrigger.cs # Proximity detection
│ │ └── BillboardLabel.cs # Name labels face camera
│ └── UI/
│ ├── DialogueUI.cs # Dialogue box with typewriter effect
│ ├── InteractionPromptUI.cs # "Press E" proximity prompt
│ └── ConnectionStatusUI.cs # API connection indicator
├── Packages/manifest.json # URP + TextMeshPro
└── ProjectSettings/ # Unity project settings
- On Play,
SceneBootstrapprocedurally creates the entire village, player, NPCs, and UI from code GameManagerconnects to the AINPCEngine API and registers all 3 NPCs with their personalities- Walking near an NPC triggers a prompt. Press E to send a
player_approachedevent - The NPC responds with AI-generated dialogue, emotion, and optional actions
- Type anything — your message is sent as a
player_dialogueevent - Emotion orbs glow with colors matching the NPC's current emotion
- Trade with Elara or accept quests from Miriam using context buttons
MIT License — Tyga.Cloud Ltd