Getting Started
This guide covers two paths:
- Quick prototype - Get an NPC talking in 10 minutes using Direct Client mode
- Production / multiplayer - Integrate through your game server using Server Mediated mode
Prerequisites
- Unity 2021.3 or later
- A LoreMind account at loremind.peekgames.dev
- SDK installed
Quick Prototype (Direct Client)
Use this to test NPC behavior quickly. For production games, use Server Mediated mode instead.
Step 1: Create an Entity Mind
- Go to loremind.peekgames.dev
- Click Entity Minds > Create
- Fill in:
- Name:
Innkeeper Garrick - Personality:
Friendly tavern keeper who loves gossip. Knows everyone in town.
- Name:
- Click Create
Step 2: Add the Component
- Create a new empty GameObject in Unity
- Name it
Innkeeper - Add Component > LoreMind NPC
- Select
Innkeeper Garrickfrom the Entity Mind dropdown
Step 3: Talk to Your NPC
Create TalkToNPC.cs:
using UnityEngine;
using Peek.LoreMind;
public class TalkToNPC : MonoBehaviour
{
[SerializeField] private LoreMindNPC npc;
void Start() => TestNPC();
async void TestNPC()
{
Debug.Log("Asking NPC a question...");
var response = await npc.RespondAsync("Hello! What's your name?");
if (response != null && response.success)
{
Debug.Log($"NPC says: {response.response}");
}
else
{
Debug.LogError($"Error: {response?.message ?? "No response"}");
}
}
}Press Play and check the Console. You should see a response.
Adding Context
NPCs give better responses with context:
npc.SetLocation("The Rusty Anvil Tavern", "Crowded and noisy");
npc.Context.timeOfDay = "evening";
var response = await npc.RespondAsync("Is it always this busy?");
// NPC responds knowing they're in a busy tavernWhen to Use Direct Client
- Prototypes and proof of concept
- Single-player games without player accounts
- Quick testing during development
Direct Client has built-in safeguards (short-lived tokens, per-device rate limits) but no player identity.
Production / Multiplayer (Server Mediated)
For production multiplayer games, integrate LoreMind through your game server.
Benefits:
| Benefit | Description |
|---|---|
| Full control | Your server decides who can interact and when |
| Your auth system | Integrate with Steam, Epic, custom accounts |
| Player identity | Tie interactions to authenticated players |
| Custom logic | Add your own validation, logging, limits |
| Secure key storage | API key stays on your server |
Note: Long-term memory requires Server Mediated mode with playerId. The client can’t be trusted to honestly identify itself.
Architecture Overview
Step 1: Create Server API Key
- Go to loremind.peekgames.dev
- Navigate to Projects > Your Project > API Keys
- Create a Server Key
- Store securely (environment variable, secrets manager)
Step 2: Implement Server Endpoint
Example in C# (ASP.NET Core):
[ApiController]
[Route("api/npc")]
public class NPCController : ControllerBase
{
private readonly HttpClient _http;
private readonly IGameStateService _gameState;
public NPCController(IHttpClientFactory factory, IGameStateService gameState)
{
_http = factory.CreateClient("LoreMind");
_gameState = gameState;
}
[HttpPost("interact")]
[Authorize] // Your auth - Steam, Epic, custom
public async Task<IActionResult> Interact([FromBody] NPCRequest req)
{
var playerId = User.GetPlayerId();
var gameContext = await _gameState.GetContext(playerId, req.LocationId);
var payload = new
{
text = req.Message,
entityMindId = req.EntityMindId,
playerId = playerId,
memory = new { retrieve = true },
context = new
{
location = gameContext.Location.Name,
timeOfDay = gameContext.TimeOfDay,
playerReputation = gameContext.PlayerReputation,
recentEvents = gameContext.RecentEvents
}
};
var response = await _http.PostAsJsonAsync("npc/interact", payload);
var result = await response.Content.ReadFromJsonAsync<LoreMindResponse>();
return Ok(new { dialogue = result.Response });
}
}Configure the HttpClient:
services.AddHttpClient("LoreMind", client =>
{
client.BaseAddress = new Uri("https://loremind.peekgames.dev/api/loremind/v1/");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
});Step 3: Unity Client
The Unity client calls your server, not LoreMind directly:
public class NPCClient : MonoBehaviour
{
[SerializeField] private string serverUrl = "https://api.yourgame.com";
public async Task<string> TalkToNPC(string entityMindId, string message)
{
var request = new { entityMindId, message, locationId = Player.CurrentLocation };
using var webRequest = UnityWebRequest.Post(
$"{serverUrl}/api/npc/interact",
JsonUtility.ToJson(request),
"application/json");
webRequest.SetRequestHeader("Authorization", $"Bearer {PlayerAuth.Token}");
await webRequest.SendWebRequest();
if (webRequest.result != UnityWebRequest.Result.Success)
{
return null;
}
var response = JsonUtility.FromJson<NPCResponse>(webRequest.downloadHandler.text);
return response.dialogue;
}
}Step 4: Rate Limiting (Your Control)
Implement rate limiting in your server:
// In your controller
if (!await _rateLimiter.TryAcquire(playerId))
{
return StatusCode(429, "Too many requests");
}See the Server Integration Guide for complete patterns including:
- Conversation session management
- Error handling and fallbacks
- Cost monitoring
- Deployment configuration
Next Steps
For Prototyping
- LoreMindNPC Component - Full component guide
- Context System - Improve response quality
For Production
- Server Integration Guide - Complete architecture
- Authentication - Server Mediated setup
- Long-Term Memory - Player memory
Creating Content
- Entity Minds - NPC personalities
- Billing - Cost management