> For the complete documentation index, see [llms.txt](https://viridian-games.gitbook.io/pixel-palette/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://viridian-games.gitbook.io/pixel-palette/core-components/appcontext.md).

# AppContext

**AppContext** is a simple message board. Any component can pin itself to the board when it wakes up, and any other component can look it up by type.

#### How it works

```
Awake() → AppContext.Register(this)    // "I exist! Here I am!"
Start() → AppContext.Get<Type>() ??=   // "I need a thing. Anyone?" 
OnDestroy() → AppContext.Unregister(this)  // "I'm gone now"
```

#### Rules

* **Register in `Awake()`** — every component pins itself to the board as soon as it wakes up, before anything tries to use it
* **Resolve in `Start()`** — look up what you need after everything has registered
* **`??=`** — if you already assigned something in the Inspector, that takes priority. AppContext is only a fallback

```
// Example: any script that needs the canvas
private DrawableCanvas canvas;

private void Start()
{
    canvas ??= AppContext.Get<DrawableCanvas>();  // Use the inspector value, or find it from AppContext
}
```

#### What's registered

Every core system registers itself:

```
DrawableCanvas, DrawingSettings, PixelArtFileIO, GridOverlay,
SelectionManager, LayerManager, AnimationManager, 
CanvasInputHandler, CanvasViewController, ConfirmPopupUGUI
```

#### Why not just FindObjectOfType?

`FindObjectOfType` is slow (scans every GameObject in the scene every time). AppContext is instant — it's just a dictionary lookup. Also, `FindObjectOfType` breaks if there are multiple scenes or if the component isn't active yet. AppContext works regardless.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://viridian-games.gitbook.io/pixel-palette/core-components/appcontext.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
