> ## 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 3: Using the NPCs

> See below for how to use both types of NPCs and handle context. 

## Swapping NPCs in Scene

The first section below covers [UI NPC Swapping](#ui-npc-swapping). If you have Open World NPCs, skip to the [**Open World NPC Swapping section**](#open-world-npc-swapping).

### UI NPC Swapping

Can be triggered on events, buttons, etc. using the functions within `NPCUIOnlySwitcher`. Use `SelectNPCByIndex` then use the index from the roster applied in `NPCUIOnlySwitcher`. 

<img src="https://mintcdn.com/gladestudio/vVHijRMN0AgbyJ0M/images/unity/Unity_NPCUIOnlySwitcherFilled.png?fit=max&auto=format&n=vVHijRMN0AgbyJ0M&q=85&s=c6e6e5ffd0248e7d5ddb3c31329dc2a8" alt="Unity NPCUI Only Switcher Filled Pn" width="773" height="247" data-path="images/unity/Unity_NPCUIOnlySwitcherFilled.png" />

And below is a NPC Roster Example from `NPCUIOnlySwitcher` .

<img src="https://mintcdn.com/gladestudio/vVHijRMN0AgbyJ0M/images/unity/Unity_NPCRosterExample.png?fit=max&auto=format&n=vVHijRMN0AgbyJ0M&q=85&s=3eb5fcd1defdcbb1b86e1b5eaae96830" alt="Unity NPC Roster Example Pn" width="778" height="67" data-path="images/unity/Unity_NPCRosterExample.png" />

Swapping to Index 0 = Roster Element 0, Lucious (NPC Chat Component).

### Open World NPC Swapping

NPC Swapping for Open World NPCs is covered by the `PlayerNPCInteractor`. Make sure to set the layer mask of each NPC to the same in the `PlayerNPCInteractor`. 

<img src="https://mintcdn.com/gladestudio/vVHijRMN0AgbyJ0M/images/unity/Unity_WorldNPCInteractorKey.png?fit=max&auto=format&n=vVHijRMN0AgbyJ0M&q=85&s=408dd099de7cd61524181a9fa44b0424" alt="Unity World NPC Interactor Key Pn" width="932" height="89" data-path="images/unity/Unity_WorldNPCInteractorKey.png" />

### Resetting Context

The section below on Context Resets applies to both UI Only NPCs and Open World NPCs.

#### Manual Context Resets

Use `ResetCurrentNPC` if you are inside or using the UI as it will also clear the chat visuals.

<img src="https://mintcdn.com/gladestudio/vVHijRMN0AgbyJ0M/images/unity/Unity_ResetCurrentNPCContext.png?fit=max&auto=format&n=vVHijRMN0AgbyJ0M&q=85&s=5ef19361ab96d3f1a95cff3754c54ac6" alt="Unity Reset Current NPC Context Pn" width="931" height="134" data-path="images/unity/Unity_ResetCurrentNPCContext.png" />

You can also use the `ResetNPC` function which is not tied to the UI from `NPCChatComponent` as it rebuilds the system prompt from scratch and clears the chat.

<img src="https://mintcdn.com/gladestudio/vVHijRMN0AgbyJ0M/images/unity/Unity_ResetNPCFunctionCode.png?fit=max&auto=format&n=vVHijRMN0AgbyJ0M&q=85&s=f74a86c1f735e5c54c2513380cc7e06f" alt="Unity Reset NPC Function Code Pn" width="931" height="276" data-path="images/unity/Unity_ResetNPCFunctionCode.png" />

### Overfill Context Options

Context needs to be managed when it gets to a context size that would not fit anymore messages. Choose a reset policy that fits your needs and edit the available options.

<img src="https://mintcdn.com/gladestudio/vVHijRMN0AgbyJ0M/images/unity/Unity_ResetContextPolicy.png?fit=max&auto=format&n=vVHijRMN0AgbyJ0M&q=85&s=255eb74c506e4e4348d4426011154d75" alt="Unity Reset Context Policy Pn" width="928" height="276" data-path="images/unity/Unity_ResetContextPolicy.png" />

<img src="https://mintcdn.com/gladestudio/vVHijRMN0AgbyJ0M/images/unity/Unity_ResetPolicyOptions.png?fit=max&auto=format&n=vVHijRMN0AgbyJ0M&q=85&s=d7cc1992cb228f2c6b1e5b420c3f523c" alt="Unity Reset Policy Options Pn" width="928" height="391" data-path="images/unity/Unity_ResetPolicyOptions.png" />

> #### Note on Open World Context Resetting
>
> Context Resetting is currently only covered by persistence conversations and overfill context policy. We have not tested context reset policies extensively enough to say our reset functions support all use cases of Open World NPCs.

### Custom Input Template

If you do not want to use our custom model trained by Glade with our emotion sliders just load your own model in the LLM Prefab or Gameobject with the LLM script on it and disable the custom template on each `NPCChatComponent` you use on your characters (see the reference below of what to turn off). Once that is off you can ignore the sliders and use your own model.  

<img src="https://mintcdn.com/gladestudio/vVHijRMN0AgbyJ0M/images/unity/Unity_CustomInputTemplateEmotionHeaderEnable.png?fit=max&auto=format&n=vVHijRMN0AgbyJ0M&q=85&s=d44fcbae64d3d68cc9f3d978f9d5ec3d" alt="Unity Custom Input Template Emotion Header Enable Pn" width="911" height="70" data-path="images/unity/Unity_CustomInputTemplateEmotionHeaderEnable.png" />
