Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

LLMUnity

> AI 编程
Open source

Create characters in Unity with LLMs!

1.7K stars0 likes0 views
WebsiteGitHub

About

Create characters in Unity with LLMs!

Create characters in Unity with LLMs!

LLM for Unity enables seamless integration of Large Language Models (LLMs) within the Unity engine.
It allows to create intelligent AI characters that players can interact with for an immersive experience.
The package includes a Retrieval-Augmented Generation (RAG) system for semantic search across your data, which can be used to enhance the character's knowledge.

The LLM backend, LlamaLib, is built on top of the awesome llama.cpp library and provided as a standalone C++/C# library.

At a glance  •  How to help  •  Games / Projects using LLM for Unity  •  Setup  •  Quick start  •  Advanced usage  •  RAG  •  LLM model management  •  Examples  •  License

At a glance

  • Runs anywhere: PC, mobile or VR!
  • ⚡ Blazing fast inference on CPU and GPU (Nvidia, AMD, Apple Metal)
  • Runs locally without internet access. No data ever leave your game!
  • Supports remote server setup
  • Supports all major LLM models
  • Advanced RAG System (ANN search)
  • Easy to setup, call with a single line of code
  • Free to use for both personal and commercial purposes

Tested on Unity: 2021 LTS, 2022 LTS, 2023, Unity 6
Upcoming Releases

Business inquiries

For business inquiries you can reach out at [email protected].

How to help

  • ⭐ Star the repo, leave a review and spread the word about the project!
  • Join us at Discord and say hi.
  • Contribute by submitting feature requests, bugs or even your own PR.
  • this work or buy me a to allow even cooler features!

Games / Projects using LLM for Unity

  • Verbal Verdict
  • I, Chatbot: AISYLUM
  • Nameless Souls of the Void
  • Murder in Aisle 4
  • Finicky Food Delivery AI
  • AI Emotional Girlfriend
  • Case Closed
  • MaiMai AI Agent System
  • Claria Chat
  • Endless Casual Drive
  • Dating App Simulator
  • Virtual Reality Mock Interview
  • Velesio AI server
  • Dungeon Chat
  • Tomonaka Desk
  • Digital Humans
  • CakeMix
  • HeyWaifu
  • Love and Lie
  • Psycho Simulator
  • False Flame
  • CielChan: Anime Desktop AI Companion

Contact [email protected] to add your project!

Setup

Method 1: Install using the asset store

  • Open the LLM for Unity asset page and click Add to My Assets
  • Open the Package Manager in Unity: Window > Package Manager
  • Select the Packages: My Assets option from the drop-down
  • Select the LLM for Unity package, click Download and then Import

Method 2: Install using the GitHub repo:

  • Open the Package Manager in Unity: Window > Package Manager
  • Click the + button and select Add package from git URL
  • Use the repository URL https://github.com/undreamai/LLMUnity.git and click Add

Quick start

1. Setup the LLM

First you will setup the LLM for your game:

  • Create an empty GameObject.
    In the GameObject Inspector click Add Component and select the LLM script.
  • Download one of the default models with the Download Model button (~GBs).
    Or load your own .gguf model with the Load model button (see LLM model management).

2. Create an AI Character

Then you can setup each of your characters as follows:

  • Create an empty GameObject for the character.
    In the GameObject Inspector click Add Component and select the LLMAgent script.
  • Define the role of your AI in the System Prompt.
  • (Optional) Select the LLM constructed above in the LLM field if you have more than one LLM GameObjects.

3. Use in Your Script

In your script you can then use it as follows:

csharp
using LLMUnity;

public class MyScript {
  public LLMAgent llmAgent;
  
  void HandleReply(string replySoFar){
    // do something with the reply from the model as it is being produced
    Debug.Log(replySoFar);
  }
  
  void Game(){
    // handle the response as it is being produced
    ...
    _ = llmAgent.Chat("Hello bot!", HandleReply);
    ...
  }
  
  async void GameAsync(){
    // or handle the entire response in one go
    ...
    string reply = await llmAgent.Chat("Hello bot!");
    Debug.Log(reply);
    ...
  }
}

You can also specify a function to call when the model reply has been completed:

csharp
  void ReplyCompleted(){
    // do something when the reply from the model is complete
    Debug.Log("The AI has finished replying");
  }
  
  void Game(){
    // your game function
    ...
    _ = llmAgent.Chat("Hello bot!", HandleReply, ReplyCompleted);
    ...
  }

To stop the chat without waiting for its completion you can use:

csharp
    llmAgent.CancelRequests();
  • Finally, in the Inspector of the GameObject of your script, select the LLMAgent GameObject created above as the llmAgent property.

That's it! Your AI character is ready to chat! ✨

Advanced usage

Build a mobile app

For mobile apps you can use models with up to 1-2 billion parameters ("Tiny models" in the LLM model manager).
Larger models will typically not work due to the limited mobile hardware.

iOS iOS can be built with the default player settings.

Android On Android you need to specify the IL2CPP scripting backend and the ARM64 as the target architecture in the player settings.
These settings can be accessed from the Edit > Project Settings menu within the Player > Other Settings section.

Since mobile app sizes are typically small, you can download the LLM model the first time the app launches. This functionality is enabled with the Download on Build option. In your project you can wait until the model download is complete with:

csharp
await LLM.WaitUntilModelSetup();

You can also receive calls the download progress during the model download:

csharp
await LLM.WaitUntilModelSetup(SetProgress);

void SetProgress(float progress){
  string progressPercent = ((int)(progress * 100)).ToString() + "%";
  Debug.Log($"Download progress: {progressPercent}");
}

This is useful to present e.g. a progress bar. The MobileDemo demonstrates an example application for Android / iOS.

Restrict the output of the LLM / Function calling / Grammar

To restrict the output of the LLM you can use a grammar, read more here.
The grammar can edited directly in the Grammar field of the LLMAgent or saved in a gbnf / json schema file and loaded with the Load Grammar button (Advanced options).
For instance to receive replies in json format you can use the json.gbnf grammar.

Alternatively you can set the grammar directly in your script:

csharp
llmAgent.grammar = "your grammar here";

For function calling you can define similarly a grammar that allows only the function names as output, and then call the respective function.
You can look into the FunctionCalling sample for an example implementation.

Access / Save / Load your chat history The chat history of a `LLMAgent` is retained in the `chat` variable that is a list of `ChatMessage` objects.
The ChatMessage is a class that defines the `role` of the message and the `content`.
The list contains alternating messages with the player prompt and the AI reply.
You can modify the chat history and then set it to your LLMAgent GameObject: ``` c# List newChat = new List(); ... llmAgent.chat = newChat; ```

To add new messages you can do:

csharp
_ = llmAgent.AddUserMessage("your user message");
_ = llmAgent.AddAssistantMessage("your assistant reply");

To automatically save / load your chat history, you can specify the Save parameter of the LLMAgent to the filename (or relative path) of your choice. The chat history is saved in the persistentDataPath folder of Unity as a json object.

To manually save your chat history, you can use:

csharp
    _ = llmAgent.SaveHistory();

and to load the history:

csharp
    _ = llmAgent.Loadistory();
Process the prompt at the beginning of your app for faster initial processing time
csharp
  void WarmupCompleted(){
    // do something when the warmup is complete
    Debug.Log("The AI is nice and ready");
  }

  void Game(){
    // your game function
    ...
    _ = llmAgent.Warmup(WarmupCompleted);
    ...
  }
Decide whether or not to add the message to the chat/prompt history

The last argument of the Chat function is a boolean that specifies whether to add the message to the history (default: true):

csharp
  void Game(){
    // your game function
    ...
    string message = "Hello bot!";
    _ = llmAgent.Chat(message, HandleReply, ReplyCompleted, false);
    ...
  }
Use pure text completion
csharp
  void Game(){
    // your game function
    ...
    string message = "The cat is away";
    _ = llmAgent.Completion(message, HandleReply, ReplyCompleted);
    ...
  }
Add a LLM / LLMAgent component programmatically
…
Use a remote server

You can use a remote server to carry out the processing and implement characters that interact with it.

**C

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#aicharacterchatchatbot

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryAI 编程
PricingOpen source

> Related tools

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.