> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gladecore.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Step 2: Setting up New NPCs

> This section covers how to setup/use NPCs for open world NPC games or UI-based games.

### **Select your NPC Setup**

The first option and section below is for creating [**UI only NPCs**](#ui-only-npcs) that don't need a full NPC character in a world. If you want to create an NPC that exists physically in the game world, select the [**Open World NPC section**](#open-world-npcs).

<CardGroup cols={2}>
  <Card title="UI Only NPCs" icon="computer" iconType="regular" href="#ui-only-npcs" />

  <Card title="Open World NPCs" icon="person-carry-box" href="#open-world-npcs" />
</CardGroup>

### UI Only NPCs

For help reference the two demo scenes named `DemoChat` and `DemoChatMobile` inside `Assets → GladeCore → Scenes`. We also provide the prefabs inside `Assets → GladeCore → DemoAssets → LLM` if you do not want to create it from scratch. Below are the steps to create UI only NPCs:

1. Add the LLM prefab or create an empty GameObject and add the scripts named `LLMServiceManager`, `LLMUnitySafeShutdown`, and `ChatHistoryLoader`. Then load the model in the LLM section like we did in the previous step. The LLM prefab needs a model applied in this script section or the inference won't work.

   <img src="https://mintcdn.com/gladestudio/ZsuGjHqdIy2sGLeQ/images/unity/Unity_LLMObjectPostDownloadExample.png?fit=max&auto=format&n=ZsuGjHqdIy2sGLeQ&q=85&s=ff3900ba0ee45d5419caba94dd24232f" alt="Unity LLM Object Post Download Example Pn" style={{ padding:"12px 0" }} width="1244" height="726" data-path="images/unity/Unity_LLMObjectPostDownloadExample.png" />

   Make sure your scene hierarchy looks the same as the one below with all your characters in the scene.

   <img src="https://mintcdn.com/gladestudio/B-bYofx2VsWLNHyV/images/unity/Unity_SceneHierarchyUIOnlyNPCs.png?fit=max&auto=format&n=B-bYofx2VsWLNHyV&q=85&s=9256ca222a0ffa88a930856bb60210c3" alt="Unity Scene Hierarchy UI Only NP Cs Pn" title="Unity Scene Hierarchy UI Only NP Cs Pn" className="mx-auto" style={{ width:"82%",padding:"12px 0" }} width="587" height="375" data-path="images/unity/Unity_SceneHierarchyUIOnlyNPCs.png" />
2. Add the `NPCSwitcher` Prefab to the scene or add an empty GameObject and add the script `NPCUIOnlySwitcher`. In the NPC Switcher make sure the below values are assigned. Once all filled out, your NPCs should be all set to use within the scene. The following "Using the NPCs" section will cover how to swap NPCs in scene and reset context.

   <img src="https://mintcdn.com/gladestudio/sqp5kgsL0GH81ySa/images/unity/Unity_NPCSwitcherUIFilled.png?fit=max&auto=format&n=sqp5kgsL0GH81ySa&q=85&s=f192cd1fd6d2ceaa4151402f4ddcbed3" alt="Unity NPC Switcher UI Filled Pn" style={{ padding:"12px 0" }} width="1240" height="354" data-path="images/unity/Unity_NPCSwitcherUIFilled.png" />
3. Add your **Canvas** by using one of the prefabs inside `Assets → GladeCore → DemoAssets → UI` (Use the non demo UI canvas so there is no demo wording). The **Canvas** is where you can edit everything from bubble sizing to panels and more. You are able to customize your own panel if you would like by swapping out the assets just to make sure that they have the corresponding fields with a content and scrollbox so that it works the same. You can also change the bubble prefabs and swap them out for buttons, different looking bubbles, or whatever you desire as it can be implemented to your needs.

   <img src="https://mintcdn.com/gladestudio/sqp5kgsL0GH81ySa/images/unity/Unity_NPCChatUICanvasFilled1.png?fit=max&auto=format&n=sqp5kgsL0GH81ySa&q=85&s=604124d3174db36aac4d3505dba894c0" alt="Unity NPC Chat UI Canvas Filled1 Pn" title="Unity NPC Chat UI Canvas Filled1 Pn" className="mx-auto" style={{ width:"94%",padding:"12px 0" }} width="1242" height="1076" data-path="images/unity/Unity_NPCChatUICanvasFilled1.png" />

   2. Look through the canvas and make sure each thing aligns with your gameplay needs. Most will not need to be changed as it has most end cases covered and is mostly cosmetic. If you do not want a close button do not assign the button and uncheck the close on escape otherwise assign the button and it will work on click or escape button. The `Enable Open Hint` field is for the "Start Chatting" that appears when opening and closing. Leave it blank for UIs that do not open and close so it does not get in the way. Make sure to enable/disable action mappings that you do not want to happen when the UI is enabled (movement or other UI systems) using `Keep Enabled Action Maps` and `Disable Action Maps`.

   <img src="https://mintcdn.com/gladestudio/X3riXwP1ARQT4LpW/images/unity/Unity_NPCChatUICanvasFilled2.png?fit=max&auto=format&n=X3riXwP1ARQT4LpW&q=85&s=49a1107c0f79f652c452988b34b37b5b" alt="Unity NPC Chat UI Canvas Filled2 Pn" style={{ padding:"12px 0" }} width="1240" height="1084" data-path="images/unity/Unity_NPCChatUICanvasFilled2.png" />

If you are only making UI Only NPCs, skip the following Open World NPC section by clicking [here](/unity/step3).

### Open World NPCs

For help reference the demo scene named DemoNPCs inside `Assets → GladeCore → Scenes`. We provide the prefabs inside `Assets → GladeCore → DemoAssets → LLM` as well if you do not want to create it from scratch.

1. Add the LLM prefab or create an empty GameObject and add the scripts named `LLMServiceManager`, `LLMUnitySafeShutdown`, and `ChatHistoryLoader`. Then Load the model in the LLM section like we did in the previous step. The LLM prefab needs a model applied in this script section or the inference won't work.

   <img src="https://mintcdn.com/gladestudio/ZsuGjHqdIy2sGLeQ/images/unity/Unity_LLMObjectPostDownloadExample.png?fit=max&auto=format&n=ZsuGjHqdIy2sGLeQ&q=85&s=ff3900ba0ee45d5419caba94dd24232f" alt="Unity LLM Object Post Download Example Pn" style={{ padding:"12px 0" }} width="1244" height="726" data-path="images/unity/Unity_LLMObjectPostDownloadExample.png" />

   If you want persistent context saved across multiple games, enable persistence and DO NOT CHANGE the Streaming subfolder from saves and location unless you change every reference in code and this is something you specifically want/need to do. Persistence needs to be enabled if you want to close the chat and come back to a chat with any NPC in the world. If it is disabled it will start a new conversation when you close and come back.
2. Add your Canvas by using one of the prefabs inside `Assets → GladeCore → DemoAssets → UI` (the Demo UI has instructions on the screen). The **Canvas** is where you can edit everything from bubble sizing to panels and more. You are able to customize your own panel if you would like by swapping out the assets just to make sure that they have the corresponding fields with a content and scrollbox so that it works the same. You can also change the bubble prefabs and swap them out for buttons, different looking bubbles, or whatever you desire as it can be implemented to your needs.

   <img src="https://mintcdn.com/gladestudio/sqp5kgsL0GH81ySa/images/unity/Unity_NPCChatUICanvasFilled1.png?fit=max&auto=format&n=sqp5kgsL0GH81ySa&q=85&s=604124d3174db36aac4d3505dba894c0" alt="Unity NPC Chat UI Canvas Filled1 Pn" style={{ padding:"12px 0" }} width="1242" height="1076" data-path="images/unity/Unity_NPCChatUICanvasFilled1.png" />

   Look through the canvas and make sure each thing aligns with your gameplay needs. Most will not need to be changed as it has most end cases covered and is mostly cosmetic. If you do not want a close button do not assign the button and uncheck the close on escape otherwise assign the button and it will work on click or escape button. The `Enable Open Hint` field is for the "Start Chatting" that appears when opening and closing. Leave it blank for UIs that do not open and close so it does not get in the way. Make sure to enable/disable action mappings that you do not want to happen when the UI is enabled (movement or other UI systems) using `Keep Enabled Action Maps` and `Disable Action Maps`.

   <img src="https://mintcdn.com/gladestudio/X3riXwP1ARQT4LpW/images/unity/Unity_NPCChatUICanvasFilled2.png?fit=max&auto=format&n=X3riXwP1ARQT4LpW&q=85&s=49a1107c0f79f652c452988b34b37b5b" alt="Unity NPC Chat UI Canvas Filled2 Pn" style={{ padding:"12px 0" }} width="1240" height="1084" data-path="images/unity/Unity_NPCChatUICanvasFilled2.png" />
3. Add your player prefab to the scene and attach the script `PlayerNPCInteractor` so that the player can interact with an NPC based on a radius or trigger box. In the NPC Switcher make sure that these values are assigned.

   <img src="https://mintcdn.com/gladestudio/DV0MDm_0jtVe_fVW/images/unity/Unity_PlayerNPCInteractorFilled.png?fit=max&auto=format&n=DV0MDm_0jtVe_fVW&q=85&s=71f363baf4e3402329d4ce61fee56a0b" alt="Unity Player NPC Interactor Filled Pn" title="Unity Player NPC Interactor Filled Pn" className="mx-auto" style={{ width:"76%",padding:"12px 0" }} width="593" height="272" data-path="images/unity/Unity_PlayerNPCInteractorFilled.png" />

Now your NPCs should be all set to use within the scene. Look at next [Using the NPCs section](/unity/step3) to understand how to use the NPCs further. (*We will update to allow new input system soon*)
