LoreMind Unity SDK
The Unity SDK provides components for integrating LoreMind-powered NPCs into your game client. For production games, the SDK typically communicates through your game server rather than directly with LoreMind.
Integration Patterns
Production: Server Mediated (Recommended)
Your game server proxies NPC requests. The Unity client talks to your server, which talks to LoreMind.
Benefits:
- Full control over who can interact and when
- Use your auth system (Steam, Epic, custom)
- Player identity for long-term memory (requires
playerId) - Custom validation, logging, limits
- API key stays on your server
See the Server Integration Guide for complete implementation patterns.
Prototyping: Direct Client
For rapid prototyping, the SDK can connect directly to LoreMind using device-based authentication. Not recommended for production.
// Direct Client mode - prototyping only
var npc = GetComponent<LoreMindNPC>();
var response = await npc.RespondAsync("Hello!");SDK Components
LoreMindNPC
Attach to any GameObject to make it an intelligent NPC:
using Peek.LoreMind;
var npc = GetComponent<LoreMindNPC>();
// Set context (works with both integration patterns)
npc.SetLocation("Blacksmith Shop", "Hot, smell of metal");
npc.Context.timeOfDay = "evening";
npc.Context.playerReputation = "trusted ally";
// Direct Client mode
var response = await npc.RespondAsync("What can you forge?");
// Or use events
npc.OnResponseReceived.AddListener(text => ShowDialogue(text));
npc.Respond("What can you forge?");RuntimeContext
Pass situational context to improve NPC responses:
npc.Context.location = "Town Square";
npc.Context.timeOfDay = "dusk";
npc.Context.weather = "rainy";
npc.Context.npcMood = "cheerful";
npc.Context.playerAppearance = "battle-worn, carrying broken sword";
npc.Context.recentEvents = new[] { "Dragon spotted nearby" };Note: In Server Mediated mode, your server typically builds this context from authoritative game state rather than trusting client-provided values.
LocationZone
Trigger-based automatic location context:
// Attach to a trigger collider
// NPCs entering the zone automatically update their location contextContextTag
Mark GameObjects as perceivable by NPCs:
// Attach to characters, items, or landmarks
// NPCs with AutoSenseNearby detect tagged entitiesLoreMindVoiceInput
Optional voice-to-text input (requires whisper.unity):
voiceInput.OnTranscription.AddListener(text => npc.Respond(text));Client Implementation (Server Mediated)
When using Server Mediated mode, the Unity client calls your game server:
using UnityEngine;
using UnityEngine.Networking;
using System.Threading.Tasks;
public class NPCClient : MonoBehaviour
{
[SerializeField] private string serverUrl;
public async Task<string> TalkToNPC(string npcId, string message)
{
var request = new NPCRequest
{
npcId = npcId,
message = message,
// Context can be sent to server or server can build it
locationId = Player.CurrentLocationId
};
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)
{
Debug.LogError($"NPC request failed: {webRequest.error}");
return null;
}
var response = JsonUtility.FromJson<NPCResponse>(
webRequest.downloadHandler.text);
return response.dialogue;
}
}Configuration
Direct Client Setup (Prototyping)
- Open Window > LoreMind > Control Panel
- Enter your Project ID
- Set Auth Mode to Direct Client
- Enter Editor API Key (for Entity Mind dropdown)
Server Mediated Setup (Production)
- Configure your game server with LoreMind API key
- Set SDK Auth Mode to Server Mediated
- Point client requests to your server URL
- Server handles all LoreMind communication
Choosing a Mode
| Consideration | Direct Client | Server Mediated |
|---|---|---|
| Setup complexity | Lower | Higher |
| Player authentication | Device-based | Your auth system |
| Rate limit control | LoreMind defaults | Your custom logic |
| Long-term memory | Not available | Full support (requires playerId) |
| Best for | Prototypes, single-player | Production, multiplayer |
Documentation
Getting Started
- Installation - Import and configure the SDK
- Getting Started - Build your first NPC
Components
- LoreMindNPC - Main NPC component
- Context System - Situational awareness
- Voice Input - Speech-to-text integration
Reference
- API Reference - Complete SDK API
Platform
- Server Integration - Production architecture
- Authentication - Auth modes explained
- Platform Overview - Dashboard and API