# 🚀 3. Quick Start Guide (Your First 10,000 Units)

In this guide, we will take a standard Unity character, convert it into a highly optimized DOTS Prefab using the **Animator Baker**, and write a simple ECS script to spawn thousands of instances on the screen.

By the end of this 5-minute tutorial, you will have a massive, fully animated crowd running at maximum FPS.

***

#### Step 1: Prepare Your Source Character

Before we can bake anything, we need a standard Unity `GameObject` set up correctly.

1. Drag your character model (FBX) into a standard Unity Scene.
2. Ensure the `GameObject` has a `SkinnedMeshRenderer`.
3. Ensure it has an **Animator** component with a valid **Animator Controller** assigned.
4. (Optional but Highly Recommended) Add an `LODGroup` component and set up your LODs. The Baker will automatically read this and generate optimized DOTS LODs!

> 💡 **Tip:** Make sure your Animator Controller has at least one animation state (e.g., "Idle" or "Run"). The Baker will read all states directly from this controller.

***

#### Step 2: Bake the DOTS Prefab

Now we will convert this standard `GameObject` into a GPU-driven DOTS Prefab.

1. Open the Baker window via **Window > Sniveler Code > Animator Baker**.
2. Drag your character `GameObject` from the scene into the **Prefab Model** field.
3. The window will populate with three tabs: `Animator`, `Lods`, and `Bones`.
4. In the `Lods` tab, ensure the **Shader** is set to Sniveler Lit (or Sniveler Unlit).
5. Click the big green **Process** button at the bottom.

**What just happened?**\
The system played through all your animations, extracted the bone matrices, and saved them into highly optimized `BlobAssets`.\
You will find your new ready-to-use DOTS Prefab in your Project window under:\
`Assets/SnivelerCode/GpuAnimation/Generated/[YourCharacterName]/Character`

***

#### Step 3: The Scene Renderer (🚨 CRITICAL STEP)

For the GPU to know how to animate your characters, the baked animation matrices must be uploaded to the video card's memory (`GraphicsBuffer`). We do this using a special scene component.

1. Create a `SubScene` in your project (Right-click in Hierarchy > New Sub Scene > Empty Scene).
2. Inside this `SubScene`, create an Empty `GameObject` and name it `GPU_Animation_Renderer`.
3. Add the `AnimatorRendererAuthoring` component to it.
4. In the **Animators** array of this component, click + and assign your newly baked DOTS Prefab.

> 🛑 **Warning:** If you skip this step, your spawned entities will not animate, or they might disappear entirely! This component is responsible for generating the `SceneAnimatorConfigData` that links your entities to the GPU buffers.

***

#### Step 4: Spawning the Crowd (C# Script)

Now let's write a simple ECS script to spawn a massive grid of our characters.

Create a new C# script named CrowdSpawnerAuthoring.cs and paste the following code:

```csharp
using SnivelerCode.GpuAnimation.Runtime.Components;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;

namespace SnivelerCode.GpuAnimation.Tutorial
{
    // 1. The Component Data (No prefab field needed here!)
    public struct CrowdSpawnerData : IComponentData
    {
        public int GridSize;
        public float Spacing;
        public bool IsSpawned;
    }

    // 2. The Authoring Component
    public class CrowdSpawnerAuthoring : MonoBehaviour
    {
        public int GridSize = 100;         // 100x100 = 10,000 units!
        public float Spacing = 1.5f;

        class Baker : Baker<CrowdSpawnerAuthoring>
        {
            public override void Bake(CrowdSpawnerAuthoring authoring)
            {
                var entity = GetEntity(TransformUsageFlags.None);
                AddComponent(entity, new CrowdSpawnerData
                {
                    GridSize = authoring.GridSize,
                    Spacing = authoring.Spacing,
                    IsSpawned = false
                });
            }
        }
    }

    // 3. The Spawner System
    [UpdateInGroup(typeof(InitializationSystemGroup))]
    public partial struct CrowdSpawnerSystem : ISystem
    {
        public void OnUpdate(ref SystemState state)
        {
            // Ensure the GPU Animation registry exists and has prefabs
            if (!SystemAPI.HasSingleton<AnimatorPrefabBuffer>()) return;
            var prefabBuffer = SystemAPI.GetSingletonBuffer<AnimatorPrefabBuffer>();
            if (prefabBuffer.Length == 0) return;

            // Grab the first registered and fully baked prefab!
            Entity characterPrefab = prefabBuffer[0].Value;

            foreach (var (spawner, entity) in SystemAPI.Query<RefRW<CrowdSpawnerData>>().WithEntityAccess())
            {
                if (spawner.ValueRO.IsSpawned) continue;

                var ecb = new EntityCommandBuffer(Unity.Collections.Allocator.Temp);
                int size = spawner.ValueRO.GridSize;
                float spacing = spawner.ValueRO.Spacing;

                // Spawn a grid of units
                for (int x = 0; x < size; x++)
                {
                    for (int z = 0; z < size; z++)
                    {
                        Entity instance = ecb.Instantiate(characterPrefab);
                        
                        float3 position = new float3(x * spacing, 0, z * spacing);
                        ecb.SetComponent(instance, LocalTransform.FromPosition(position));
                    }
                }

                ecb.Playback(state.EntityManager);
                ecb.Dispose();

                // Mark as spawned
                spawner.ValueRW.IsSpawned = true;
            }
        }
    }
}
```

> 💡Notice that our Spawner doesn't need a Prefab field! It automatically queries the `AnimatorPrefabBuffer` to grab the exact entity that was processed and uploaded to the GPU by your Scene Renderer.

**Final Setup:**

1. Create another Empty `GameObject` in your **SubScene**.
2. Attach the `CrowdSpawnerAuthoring` script to it.
3. Drag your **Baked DOTS Prefab** into the Character Prefab slot.
4. Set the Grid Size to 100 (which will spawn 10,000 units).

***

#### Step 5: Press Play! ▶️

Hit the Play button in the Unity Editor.

You should instantly see a massive grid of 10,000 characters, all animating smoothly. Because the animation logic is handled entirely by the GPU and Burst-compiled jobs, your CPU frame time should remain incredibly low.

**Congratulations!** You have successfully integrated GPU Animation Entities PRO into your project.


---

# 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/3.-quick-start-guide-your-first-10-000-units.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.
