---
title: "GPU-instance animated characters with different poses in C#"
url: https://recursiveai.org/onegame/cookbook/draw-skinned-model-instances-with-different-poses/
description: "Draw multiple copies of one skinned glTF character in OneGame. Use GPU instancing while sampling a different animation pose for each copy in C#."
version: "2.5.3"
---

Use `AddSkinnedInstanced` to share one character mesh while giving each copy its own skeleton pose.

```shell
dotnet add package RecursiveAI.OneGame.Host
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

Use `Fox.glb` from the zip. The example uses Vulkan.

```csharp
using OneGame.Gltf;
using OneGame.Render3D;
using RecursiveAI.OneGpu;
using M = System.Numerics.Matrix4x4;

using var gpu = GpuBackends.CreateDevice();
using var renderer = new Renderer3D(gpu);
var asset = GltfLoader.LoadFile("Fox.glb");
using var model = renderer.Upload(asset);
var scene = new Scene3D();
var batch = scene.AddSkinnedInstanced(
    model, 2);
var pose = asset.CreateRestPose();
var scale = M.CreateScale(0.04f);
// Walk
asset.Animations[1].Apply(pose, 0.25f);
var left = M.CreateTranslation(-2.5f, 0, 0);
batch.Add(scale * left, pose);
// Run
asset.Animations[2].Apply(pose, 0.50f);
var right = M.CreateTranslation(2.5f, 0, 0);
batch.Add(scale * right, pose);
Console.WriteLine(
    $"Skinned batch: {batch.Posed}");
Console.WriteLine($"Copies: {batch.Count}");
```

Adds a walking pose on the left and a running pose on the right. Prints:

```text
Skinned batch: True
Copies: 2
```

Unzip [the example](https://recursiveai.org/onegame/cookbook/draw-skinned-model-instances-with-different-poses/draw-skinned-model-instances-with-different-poses.zip), then `dotnet run`.

## Full program

The full program lights the scene and renders the two copies to an image. `Fox.glb` includes one skin with 24 joints, the mesh and textures, and three clips: `Survey`, `Walk`, and `Run`. The [Fox sample](https://github.com/KhronosGroup/glTF-Sample-Assets/tree/8f492390ddc7a2ae221a1369ef560589cf8c70fb/Models/Fox) is distributed unchanged with its credits and licenses in the zip.

`RecursiveAI.OneGame.Host` brings in the `OneGame.Gltf`, `OneGame.Render3D`, and `RecursiveAI.OneGpu` APIs, so you don’t need to install them separately.

On Linux and Windows, the full program needs a working Vulkan driver. On Linux with no Vulkan driver available, OneGame 2.5.3 stopped before rendering with `GpuUnsupportedException: vkCreateInstance failed: ErrorIncompatibleDriver`.

```csharp
using System.Numerics;
using System.Linq;
using OneGame.Gltf;
using OneGame.Render3D;
using RecursiveAI.OneGpu;

using var device = GpuBackends.CreateDevice();
using var renderer = new Renderer3D(device);
var asset = GltfLoader.LoadFile("Fox.glb");
using var model = renderer.Upload(asset);
var scene = new Scene3D { Samples = 1 };
var batch = scene.AddSkinnedInstanced(model, capacity: 2);
var pose = asset.CreateRestPose();
var walk = asset.Animations.Single(clip => clip.Name == "Walk");
var run = asset.Animations.Single(clip => clip.Name == "Run");
var scale = Matrix4x4.CreateScale(0.04f);
walk.Apply(pose, 0.25f);
var left = batch.Add(scale * Matrix4x4.CreateTranslation(-2.5f, 0, 0), pose);
run.Apply(pose, 0.50f);
batch.Add(scale * Matrix4x4.CreateTranslation(2.5f, 0, 0), pose);
Console.WriteLine($"Skinned batch: {batch.Posed}; copies: {batch.Count}");

scene.Camera = Camera3D.LookAt(new(6, 4, 11), new(0, 1, 0), Vector3.UnitY);
scene.Environment.Background = BackgroundMode.Color;
scene.Environment.BackgroundColor = new(0.05f, 0.10f, 0.12f);
scene.Post.Bloom = false;
scene.Lights.Add(Light3D.Directional(new(-0.5f, -1, -0.4f), Vector3.One, 3));
using var target = new Offscreen3D(renderer, 320, 180);
var pixels = target.Capture(scene);
Console.WriteLine($"Rendered instances: {renderer.LastStats.Instances}");
using var output = File.Create("foxes.ppm");
output.Write("P6\n320 180\n255\n"u8);
for (int i = 0; i < pixels.Length; i += 4) output.Write(pixels, i, 3);
Console.WriteLine("Wrote foxes.ppm (320 x 180)");
```

```text
Skinned batch: True; copies: 2
Rendered instances: 2
Wrote foxes.ppm (320 x 180)
```

If `batch.Posed` is false, check that your glTF has a skin; passing a pose to a model without a skin won’t animate it in this batch.

## Variations

To update just the left fox, insert this before `target.Capture(scene)` in the full program. Keep the index returned by `Add` so you can change that copy without moving it:

```csharp
walk.Apply(pose, 0.75f);
batch.SetPose(left, pose);
```

## Related recipes

- [Animate a glTF character in C#](https://recursiveai.org/onegame/cookbook/animate-gltf-character/)
- [Blend walk and run animations in C#](https://recursiveai.org/onegame/cookbook/blend-walk-run-animation/)

## The short answer

Upload one skinned model and pass it to `Scene3D.AddSkinnedInstanced`. Sample a clip into a `NodePose`, then pass that pose and a transform to the batch’s `Add`. Sample another clip or time and add the next copy. OneGame reads the pose when you call `Add`, so you can reuse the same `NodePose` without making the first fox switch to the second fox’s pose.

## How do you render an animated crowd with GPU instancing?

Separate what the characters share from what changes per character. The mesh and skin belong to the model you upload once. Each copy gets its own transform in the world and its own set of joint transforms for that frame. The GPU uses those joint transforms to bend the shared vertices into the correct pose for the copy it’s drawing. The batch submits one instanced draw per visible primitive per view, not necessarily one draw for the entire model; shadow views can draw the same batch again.

Use `AddSkinnedInstanced`, not `AddInstanced`, for this job. The ordinary batch renders at the model’s rest pose. In a skinned batch, a copy added without a pose also stays at rest. Keep the instance scale uniform and unmirrored. Morph targets and nodes without a skin stay at rest in the batch, so choose a separate model instance if you need those parts to animate or if you need to pick an individual character with the scene’s picking API.

## How do you give each instance a different animation pose?

Keep animation time per character. Sample each character’s clip at its own time and call `SetPose` on that character’s index each frame. This lets two characters share a walk clip without stepping in sync, or lets one walk while another runs. Changing your local `NodePose` alone won’t update a copy that’s already in the batch; you must pass the new pose to the batch. Use `Set` with both the transform and the pose when you are also moving the copy.

If a character vanishes near the edge of the view in a pose that reaches far beyond the rest model, check `BoundsMargin`. OneGame tests visibility using the rest bounds expanded by this margin, not exact bounds recomputed from every bent vertex. Increase the margin to cover the reach of the animation. Don’t use a very large margin by default: it keeps copies in the draw even when their geometry is outside the view.
