Skip to Content
DocsLoremind SdkLoreMind Unity SDK

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

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 context

ContextTag

Mark GameObjects as perceivable by NPCs:

// Attach to characters, items, or landmarks // NPCs with AutoSenseNearby detect tagged entities

LoreMindVoiceInput

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)

  1. Open Window > LoreMind > Control Panel
  2. Enter your Project ID
  3. Set Auth Mode to Direct Client
  4. Enter Editor API Key (for Entity Mind dropdown)

Server Mediated Setup (Production)

  1. Configure your game server with LoreMind API key
  2. Set SDK Auth Mode to Server Mediated
  3. Point client requests to your server URL
  4. Server handles all LoreMind communication

Choosing a Mode

ConsiderationDirect ClientServer Mediated
Setup complexityLowerHigher
Player authenticationDevice-basedYour auth system
Rate limit controlLoreMind defaultsYour custom logic
Long-term memoryNot availableFull support (requires playerId)
Best forPrototypes, single-playerProduction, multiplayer

Documentation

Getting Started

Components

Reference

Platform

Last updated on