Local LLM NPC Dialogue
University project · NPC dialogue
This Unreal Engine project connects NPC dialogue to a locally hosted language model through a C++ service interface. Blueprint properties define each character's identity, background and speaking style. The dialogue handler combines those settings with recent conversation history to construct a JSON request, which Unreal's HTTP module sends to Ollama using the Mistral model.
The response is processed incrementally, allowing the Blueprint dialogue interface to display text while generation is still in progress. Each of the eight NPCs maintains its own conversation history. The handler also limits reply length and cleans up incomplete exchanges when requests fail or are cancelled, keeping subsequent prompts consistent.
Technical highlights
- NPC personalities, backstories and speaking styles can be configured in Blueprints.
- Responses stream into the dialogue interface as they are generated.
- Each NPC keeps a separate conversation history and reports connection or model errors clearly.
Technical details
Character dialogue
Each NPC builds a system prompt from its identity, occupation, traits and speaking instructions. The dialogue handler combines this with recent exchanges and sends a JSON request through Unreal Engine's HTTP module. The service interface keeps the NPC logic separate from the LLM implementation.
Streaming and memory
The handler reads response chunks as they arrive, applies sentence limits and sends new text to the Blueprint interface. Completed replies enter that NPC's history. Failed or cancelled requests remove the unfinished message so that the next conversation does not include an incomplete exchange.
Project context
Requires Ollama and the Mistral model running locally. Memory is limited to recent exchanges during the current play session. Response quality and speed vary with the model and the available hardware.