# 🎛️ 4. The Animator Baker Window

The **Animator Baker** is the heart of GPU Animation Entities PRO. Since the GPU needs pre-calculated data to animate thousands of units without CPU overhead, this window handles the heavy lifting: it plays through your animations, extracts the bone matrices, configures the Shader Graph materials, and generates a ready-to-use DOTS Prefab.

You can open the tool via the top menu: **Window > Sniveler Code > Animator Baker**.

***

#### 📦 The Source Prefab

To start, drag and drop a standard Unity `GameObject` from your scene or project into the **Prefab Model** field.

> ⚠️ **Requirement:** The source `GameObject` must contain a `SkinnedMeshRenderer`. If it contains an `Animator` component with an assigned `Controller`, the `Baker` will automatically detect it. If it has an `LODGroup`, the Baker will import your LOD levels automatically.

Once a valid prefab is assigned, the window will unlock three configuration tabs: `Animator`, `Lods`, and `Bones`.

***

#### 🎬 Tab 1: Animator Settings

This tab controls how your animations are baked and processed.

* **Animator Controller:** The Unity Animator Controller containing the states you want to bake. The tool automatically reads all states from the **base layer**.
* **Use Dual Quaternion (DQS):**
  * Enabled (Recommended for organic characters): Uses Dual Quaternion Skinning. Prevents the "candy-wrapper" effect where joints (shoulders, elbows) lose volume when twisted.
  * Disabled (Recommended for mechs/hard-surface): Uses standard Linear Blend Skinning (LBS). Slightly faster on the GPU but can cause volume loss on extreme bends.
* **Apply Root Motion:** If enabled, the Baker extracts the root movement of the animation and saves it as a `RigidTransform` delta. At runtime, the `AnimatorRootMotionSystem` will physically move your Entity's LocalTransform based on the animation.
* **Animation Clips List:**
  * **FPS Slider:** Controls the sampling rate. A 60 FPS bake is buttery smooth but takes more memory. For distant crowds or simple movements, dropping this to 30 FPS can save 50% of the memory footprint!

***

#### 📉 Tab 2: LODs (Level of Detail)

Performance is everything. This tab allows you to configure how your mesh degrades at a distance to save GPU ALU instructions.

* **Shader Selection:** Choose the base material for your generated prefab.
  * **Sniveler Lit**: Standard URP Lit shader with animation support.
  * **Sniveler Unlit**: Cheap unlit shader for maximum performance.
  * Custom: Allows you to assign your own Shader Graph material (See **5. Shader Graph Integration** for details).
* **Transition %:** The screen-size percentage at which this LOD becomes active (matches Unity's standard `LODGroup`).
* **Quality (Bone Influences):**
  * **4 Bones**: Highest quality. Every vertex is influenced by up to 4 bones.
  * **2 Bones**: Great for mid-distance.
  * **1 Bone**: Extremely cheap. Perfect for massive distant swarms.
* **Interpolation:** If enabled, the shader smoothly blends between animation frames. If disabled `_SNIVELER_ANIM_STEP`, the animation updates in discrete steps. Disabling this on distant LODs saves significant GPU processing power.
* **Shadows:** Toggle whether this specific LOD casts shadows.
  * Note: The system automatically forces 1-Bone, non-interpolated skinning for the `Shadow Caster` pass to ensure shadows are rendered as cheaply as possible!

***

#### 🦴 Tab 3: Bones (Sockets Setup)

This tab is crucial if you plan to attach weapons, armor, or particle effects to your units later.

By default, GPU skinning happens entirely on the video card, meaning the CPU doesn't know where the character's hands or head are.\
By adding a bone to the **Bake List** in this tab, the `Baker` will save that specific bone's exact position and rotation for every frame into the `BlobAsset`.

1. Click **Add the bone to the bake list**.
2. Select the desired bone from the dropdown (e.g., `RightHand_Bone`, `Spine`, `Head`).
3. At runtime, our Zero-Latency Socket System will use this data to attach items perfectly. (We will cover this in detail in **6. Sockets & Attachments**).

***

#### 💾 The Output: What Happens When You Click "Process"?

When you click the green **Process** button, the tool does the following:

1. Creates a new folder in your project: `Assets/SnivelerCode/GpuAnimation/Generated/[YourPrefabName]`.
2. Bakes all animation matrices and root motion data into a `AnimatorMatrices.asset`.
3. Generates optimized Shader Graph materials for each LOD.
4. Creates a **DOTS-ready Prefab** in the Character subfolder.
5. Generates a C# script (`GeneratedParams.cs`) containing static byte IDs for your animations and parameters, so you don't have to use strings in your code!


---

# Agent Instructions: 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://sniveler-code.gitbook.io/dots/gpu-animation-entities-pro/4.-the-animator-baker-window.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.
