MasterNin ECSAnimator
On this page

ECSAnimator API reference

Use the Quick Start for your first character and Gameplay integration to choose a route. This reference covers runtime ownership and advanced APIs. Check the support matrix for source-feature restrictions.

Namespaces: ECSAnimator.Runtime.Product.ECS for runtime/client/commands, ECSAnimator.Runtime.Product.Data for EntityDesc/Settings, and Asterism.Editor.OfflineBuild.Convert for the Editor conversion window/plan. Application code references ECSAnimator.Runtime.Product plus the Unity assemblies it uses: Unity.Entities/Unity.Mathematics for the spawn example, Unity.Transforms for movement, Unity.Burst for Burst jobs and Unity.Collections for NativeArray. Conversion extensions also reference ECSAnimator.Offline.Build and ECSAnimator.Package.Contract. All assemblies set autoReferenced: false, so put consuming code in an asmdef and add the reference explicitly.

First-time users should start with Getting started and the shipped SimpleCharacterExample.cs, which includes setup, movement and cleanup instead of isolated snippets. For step-by-step instructions, see Animation integration and Conversion and component support. Runtime-loaded EntityDesc assets use the same APIs; see resource-manager loading and unloading.

API Purpose
CharacterRuntime.TryGet(World, ...) Gets the single ECSAnimator facade for one live World.
TryPrepare(CharacterRuntimeAsset, ...) Hydrates and retains one reusable character asset.
CharacterPreparedAsset.RuntimeResource Reads compiled public metadata while the prepared bindings remain live; null when stale/released.
TryCreateScope(expectedCount, ...) Creates a caller-owned group of spawned characters.
TrySpawn / TrySpawnBatch Creates character roots from CharacterSpawnRequest; presentation owns their EG render children.
TryResolve(CharacterInstanceHandle, ...) Resolves a stable handle when an Entity is actually required.
TryCreateAnimationClient(...) Resolves declared exact Controller binding keys once and creates one command lane.
CharacterAnimationClient.TryBind(...) Binds one live target to a main-thread CharacterAnimator.
CharacterAnimationClient.Dispose() Stops/disposes the client and releases its prepared-asset hold; do this before Release.
Destroy / DestroyScope Requests instance destruction without exposing renderer ownership.
Release(CharacterPreparedAsset) Returns whether entityDesc/resource retirement was requested.
prepared.ReleaseState / ReleaseDetail Read Active, Pending, Released, FaultedRetainedRequiresWorldRebuild or Invalid directly on the prepared object.

CharacterRuntime, CharacterPreparedAsset, CharacterSpawnScope and handles are World-bound. Do not reuse them after destroying or recreating that World. Repeated TryGet returns the same facade. Removing/replacing internal ECSAnimator systems in a live World is unsupported; rebuild the entire World instead. Detached release tickets and their bounded history are removed; retain the prepared object when release status is needed.

Cleanup order: stop/unregister producers, Dispose animation clients, Destroy/DestroyScope, then Release prepared assets. Continue normal World updates while a release is Pending; never busy-wait. If the World was already disposed, discard its facade/handles and do not call its EntityManager.

if (!CharacterRuntime.TryGet(world, out var runtime, out var error) ||
    !runtime.TryPrepare(entityDesc, out var prepared, out error) ||
    !runtime.TryCreateScope(100, out var scope, out error))
    throw new InvalidOperationException(error);

var requests = new CharacterSpawnRequest[100];
for (var i = 0; i < requests.Length; i++)
    requests[i] = new CharacterSpawnRequest(new float3(i, 0, 0), quaternion.identity, 1f);

if (!runtime.TrySpawnBatch(prepared, requests, scope, null, out var spawned, out error))
    throw new InvalidOperationException(error);

Clothing color at spawn

CharacterSpawnRequest(position, rotation, scale, clothingColor) accepts linear RGB in [0,1]; the fourth channel is tint strength, where 0 preserves the material and 1 replaces the masked cloth hue while retaining its shading. The three-argument constructor preserves existing appearance. For a Unity Inspector Color, convert with .linear before passing its RGB values.

var request = new CharacterSpawnRequest(position, rotation, 1f,
    new float4(0.02f, 0.20f, 0.95f, 1f));
runtime.TrySpawn(prepared, request, scope, null, out var character, out var error);

The source ECSAnimator/Lit material must enable Clothing Tint and assign a linear _ClothingMask texture (red channel: white = cloth, black = protected). It shares _BaseMap UV scale/offset. _ECSAnimClothingColor also provides the material preview/default color. Rebuild the offline asset after changing these inputs. The renderer sets the color independently on each character's render children; it does not clone materials per faction or update color every frame. Characters without a spawn override have no additional color component. This input sets the initial appearance; runtime color mutation is not exposed by this API.

Animation commands

Create one CharacterAnimationClient per producer/asset, not per character. Declare exact Controller parameter names, layer names or full exported state paths with TryCreateAnimationClient. Main-thread code binds a target and uses those declared keys.

TryBind returns a frame-scoped writer, not a persistent Unity Animator. Bind again each frame, once per client in that frame; do not cache the writer across updates or use the single-target entry for a crowd. Use TryReserveTargets for batch/Jobs. Missing, duplicate or ambiguous keys are rejected at client registration. No Template or gameplay-alias asset is involved.

if (!client.TryBind(character, out var animator, out error) ||
    !animator.TrySetFloat("Speed", speed, out error))
    throw new InvalidOperationException(error);

CharacterAnimator supports TrySetFloat, TrySetInt, TrySetBool, TrySetTrigger, TryResetTrigger, TrySetLayerWeight, TryPlay, TryPlayFixedTime, TryCrossFade, and TryCrossFadeFixedTime. For jobs, cache ResolvedAnimationHandle values with TryGet, reserve once with TryReserveTargets, write through CharacterAnimationParallelWriter.Begin, and call RegisterProducer(JobHandle).

CharacterAnimatorWriter supports:

Use NextRequest() for direct writer one-shot identity, then call TryGetReceipts once per consumption batch and use Matches before acknowledging gameplay intent. Its buffer is read-only and must not be retained across updates. ReceiptCount and TryGetReceipt remain available for individual queries.

Each character has one business writer per frame. Resolve AI/player priorities before writing. Commands from that writer are applied in reservation/append order; repeated continuous values use last-write order. Two writers targeting the same character reject that character's entire command set (Conflict for one-shots). Cross-character producers remain parallel; no global sorting or multi-writer coalescing is performed. Writer identities are process-local counters, not stable-key hashes; recreating a client cannot reuse its old requests. At input-generation exhaustion, all new commands return Fault and the character must be recreated.

Read-only animation state is exposed by CharacterAnimationObservation: TryGetLayer, IsInState, IsInTag, IsActionPlaying, CountEvent, TryGetEventOccurrence, TryGetEventOccurrences, WasTriggerConsumed, and TryGetConsumedTrigger. Animation observations are presentation feedback, not gameplay authority.

For a batch of events, call TryGetEventOccurrences once, then use MoveNext(out occurrence, out metadata). The enumerator validates the binding and generation, preserves occurrence order and duplicate keys, and borrows the current read-only occurrence buffer. Consume it before the next update or structural change.

CharacterDynamicPackingSystem.TryCopyCurrentWords replaces TryCopyPublishedWords. The requested generation must still occupy the CPU work buffer; every new Pack attempt invalidates the prior capture, including failed attempts. Pending data never stands in for an older published generation. LocalResolve palettes remain evaluator-owned. GPU diagnostics capture their own expected data on request and retain the exact GPU lease until readback completes; the runtime keeps no published CPU mirror.

State and transition lifecycle feedback is exposed through CharacterLifecycleOccurrence: StateEnter, StateExit, TransitionStart, and TransitionEnd are emitted without per-instance configuration. Add CharacterLifecycleSubscription only when per-update StateUpdate records are required. Consume the buffer in CharacterEventSystemGroup; this is the ECS bridge for presentation side effects and does not execute arbitrary StateMachineBehaviour managed code.

AI, behaviour tree and movement integration

Move/intent producers belong in CharacterAnimationIntentProducerSystemGroup, before Unity TransformSystemGroup; animation bridges then run before evaluation. The simple sample has a Burst ISystem movement example. Its MonoBehaviour animation writes are consumed by a subsequent ECS update; use the dedicated bridge group when same-Simulation ordering is required.

Project systems own AI state and LocalTransform. A single system in CharacterAnimationBridgeSystemGroup translates project intent into ECSAnimator commands. Presentation-event consumers run in CharacterEventSystemGroup. No AI or movement system needs a GPU buffer, BRG system, Blob layout, or Shader ABI reference.

Prototype and spawn customization

Implement ICharacterPrototypeCustomizer to add unmanaged ECS components or buffers once through CharacterPrototypeBuilder. Its PrototypeCustomizationId must change whenever the resulting configuration changes, including default values as well as the archetype. Implement ICharacterSpawnInitializer to populate those declared values through CharacterSpawnValueWriter for each new instance. ECSAnimator topology, cleanup, transform and renderer-owned material-property components cannot be replaced through this seam.

Attachments and authoring

The custom evaluator intentionally does not claim arbitrary Unity Animator equivalence. Synced and additive layers, transition interruption and state-machine routes, dynamic state speed/mirror/time/cycle-offset, Write Defaults Off history, and 2D/Direct BlendTrees have deterministic runtime implementations, with support bounded by the Unity-oracle qualification matrix for the chosen Unity version. See the current support table and limits; this is not a promise of arbitrary Animator combinations. StateMachineBehaviour, controller IK Pass, state Foot IK and Apply Root Motion are omitted without rejecting the remaining skeletal animation. Inspect preview findings and OfflinePackageBuildResult.OmittedFeatures; the conversion window also displays a completion dialog. Source Prefabs/Controllers are unchanged and state scripts are not executed during sampling. Out-of-envelope Humanoid Hips displacement and arbitrary non-transform/ObjectReference curves still produce actionable errors instead of silently publishing a wrong character. Exact Root and hand/foot goal channels from a compatible Humanoid clip/avatar are Unity offline-sampler inputs: their resulting bone matrices are baked, without adding runtime root-motion or IK execution. The lifecycle occurrence bridge replaces common enter/exit/update side effects but does not execute behaviour classes.

Runtime pose constraints

Add CharacterBoneYaw and/or a CharacterTwoBoneIK buffer to the spawned root entity. They run in the existing Burst evaluation job after state/layer blending and before bind matrices, GPU transport and sockets. Animator history stores the uncorrected animation; disabling/removing the components restores animation on the next evaluation. There are no bone GameObjects or managed per-bone callbacks at runtime.

Use an offline LocalResolve asset. Enable Require Pose Processing on the Convert Preset, or pass requirePoseProcessing: true to the explicit discovery overload. This produces the required local-pose data even for a simple Controller; no dummy parameter is needed. Other supported Controller configurations can also select LocalResolve. Check prepared.SupportsPoseProcessing before installation. The compact MatrixInline2 payload has no local pose samples; adding active constraints to it faults evaluation rather than silently doing nothing. Reconvert and prepare the resource again if the capability is missing.

// Resolve these indices once from markers exported for this exact prepared character.
prepared.RuntimeResource.TryFindAttachment("ik.right.upper", out var upper);
prepared.RuntimeResource.TryFindAttachment("ik.right.mid", out var forearm);
prepared.RuntimeResource.TryFindAttachment("ik.right.tip", out var palm);
var ik = entityManager.AddBuffer<CharacterTwoBoneIK>(spawned.Entity);
ik.Add(new CharacterTwoBoneIK {
    RootBoneIndex = upper.GeometryBoneIndex,
    MidBoneIndex = forearm.GeometryBoneIndex,
    TipBoneIndex = palm.GeometryBoneIndex,
    TargetPosition = new float3(.45f, 1.7f, .35f), // character-root space
    TargetRotation = quaternion.identity,        // unit quaternion in root space
    HintPosition = new float3(.95f, 1.4f, -.1f),
    Weight = 1f
});

Check every TryFindAttachment result before using its index. Root/Mid/Tip must be a direct two-segment chain in that skeleton. Inputs must be finite, rotation normalized, and Weight in [0,1]. Weight zero retains animation; nonzero weights blend position and tip rotation. The elbow hint selects the bend plane, with a finite fallback for collinear hints. Unreachable targets clamp to the available segment lengths; limbs do not stretch. Invalid chains/inputs fail the character's evaluation without publishing a valid new pose.

CharacterBoneYaw specifies BoneIndex, AngleRadians and Weight; it rotates that bone and its descendants about the character-root Y axis. Gameplay supplies/clamps the angle. Two-bone constraints then execute in buffer order. Supply inputs before the character evaluation, normally from CharacterAnimationBridgeSystemGroup; respect job dependencies when writing buffers. Targets in world space must first be transformed by the inverse character root transform. Animation LOD also limits constraint evaluation frequency.

See Demo14 for two arm chains, barrel calibration, a moving target, attack-state gating and foregrip observations. This API does not execute OnAnimatorIK, Animator IK Pass, Foot IK or converted Animation Rigging components, and does not implement automatic ground adaptation.

Custom pose post-processing (preview)

CharacterPoseProcessor is an optional enableable root component. Its Function is a FunctionPointer<CharacterPoseProcessorFunction> compiled from a static Burst-compatible method. Install it together with a CharacterPoseProcessorData byte buffer only on characters that need processing. Characters without these components keep their existing evaluation path; resources prepared for pose processing can also run without an installed processor.

The callback executes once per due character evaluation in the existing parallel Burst job: Animator blending and raw history -> existing yaw/two-bone constraints -> custom processor -> inverse bind -> skinning, sockets and GPU transport. It receives a temporary CharacterPoseStream, its own data pointer and byte count. Return exactly 1 for success. Public stream-access failures are retained even if the callback ignores a false return. A failed callback does not publish a valid new pose or sockets. Existing mutable animation state and business data are not transactionally rolled back; validate first and write persistent state only after the pipeline succeeds.

Compile and cache the function once during setup, then install it at a safe main-thread spawn point or declare it through the prototype extension. A small business implementation is:

using AOT;
using Unity.Burst;
using ECSAnimator.Runtime.Product.ECS;

public struct AimData { public CharacterTwoBoneIK Arm; }

[BurstCompile]
public static unsafe class AimPose
{
    [BurstCompile]
    [MonoPInvokeCallback(typeof(CharacterPoseProcessorFunction))]
    public static int Process(ref CharacterPoseStream pose, byte* bytes, int byteCount)
    {
        if (!pose.TryReadData<AimData>(bytes, byteCount, out var data)) return 0;
        return pose.TrySolveTwoBone(data.Arm) ? 1 : 0;
    }
}

At a safe spawn point:

// Setup only. Cache this handle; do not compile it per character or frame.
var function = BurstCompiler.CompileFunctionPointer<CharacterPoseProcessorFunction>(AimPose.Process);
if (!prepared.SupportsPoseProcessing)
    throw new System.InvalidOperationException("Reconvert with Require Pose Processing enabled.");
entityManager.AddComponentData(spawned.Entity, new CharacterPoseProcessor { Function = function });
var dataBuffer = entityManager.AddBuffer<CharacterPoseProcessorData>(spawned.Entity);
CharacterPoseProcessorData.Set(dataBuffer, new AimData { Arm = armConstraint });
// Later, skip the callback without removing the components:
entityManager.SetComponentEnabled<CharacterPoseProcessor>(spawned.Entity, false);

The setup fragment assumes an already prepared/spawned character and a validated armConstraint. The business assembly needs unsafe code enabled and references to ECSAnimator.Runtime.Product, Unity.Burst, Unity.Entities, Unity.Collections and Unity.Mathematics. Check bone bindings as in the constraint example above. Use your own unmanaged data structure for targets, weights and persistent solver state. CharacterPoseProcessorData.Set<T> and TryGet<T> copy that exact structure; CharacterPoseStream.TryReadData<T> / TryWriteData<T> do the same inside the callback. Update target fields while preserving existing state, and respect the evaluator's read/write dependencies. Do not retain a DynamicBuffer or stream across structural changes/frames.

TryGetParent, TryReadRootMatrix and TryWriteRootMatrix operate on this resource's exported skeleton in character-root space. Writing one matrix changes that bone only; RotateSubtree rotates its descendants as well. TryApplyYaw and TrySolveTwoBone reuse the supported helpers. The view hides the internal packed pose representation and rejects invalid indices, nonfinite or unrepresentable affine writes. For iterative solvers, perform iterations in float scratch data and write the final result rather than repeatedly quantizing intermediate poses.

RootToWorld converts root-space targets to/from world space. DeltaTime is the accumulated evaluation time consumed after animation LOD skips, not necessarily the current frame delta. Generation identifies this evaluation's proposed pose generation. LOD skips reuse the previously committed pose and do not run the callback. Target/physics producers normally run in CharacterAnimationBridgeSystemGroup; choose a suitable animation LOD when frequent target response is required.

Compose several algorithms in the business callback in the desired order. To control the complete constraint order, omit the legacy yaw/two-bone root components and call their stream helpers in your pipeline. This supports independent-character bone algorithms, not a runtime PlayableGraph. No managed delegates, GameObjects, structural ECS changes, retained raw pointers, or current-frame cross-character pose dependencies are allowed inside the parallel callback. Terrain queries and other inputs belong in producer systems. Root Motion, new animation property channels and arbitrary runtime clip graphs are separate capabilities and are not supplied by this hook.

Only CharacterPoseProcessor and CharacterPoseProcessorData are exceptions to the prototype guard against package-owned types: declare them using CharacterPrototypeBuilder.Add / AddBuffer, then initialize declared values through CharacterSpawnValueWriter. SetEnabled can set the prototype default. Other package-owned types remain protected. This API is preview; processing has its own algorithm and indirect-call costs, and no zero-overhead or blanket Player/AOT qualification is claimed. See Burst function-pointer requirements.

Editor conversion API

Multiple Animator components do not block discovery. A valid Preset Animator Path takes priority; otherwise the first component in prefab hierarchy order (including inactive children) is selected. The other controllers are omitted, and their preview-clone Animators are disabled. The whole Prefab hierarchy/renderers remain in scope; this does not split assets or export independent child animation. Ignored GameObject behaviours are listed in preview and OfflinePackageBuildResult.OmittedFeatures. The window keeps completion warnings inline/in Console without a confirmation dialog. Invalid controller, geometry, shader, LOD and artifact-integrity data still require correction.

CharacterConversionDiscovery.Discover(prefab, preset) is pure preview and returns a CharacterConversionPlan with findings, memory estimates, and CanBuild. Inspect findings for NeedsVerification; the former CanVerify convenience property is removed. Use the plan's Build; on success, load result.AssetPath as CharacterRuntimeAsset using AssetDatabase.LoadAssetAtPath in the Editor. Build rediscovers the current Prefab/preset and captures the full source identity once, then resolves the fixed last-green backup. Do not change source assets or presets during Build, including from progress callbacks; cancellation remains supported. The explicit Discover overload supplies an explicit product key plus separate allowed/requested output roots for tools such as imported Samples. Its optional fifth argument, requirePoseProcessing, defaults to false. CharacterConvertPreset.RequirePoseProcessing and OfflineBuildInput.RequirePoseProcessing select the same option. The validated request captures it, source identity includes an enabled option, and Build refresh preserves it. V6 already represents LocalResolve; no format upgrade or runtime automatic promotion is performed.

The lower-level OfflinePackageBuildApi remains available to custom producers that already own an OfflineBuildInput and attachment array. Both paths preserve the same candidate validation, automatic fixed-backup recovery and last-green behavior. Check OfflinePackageBuildResult.IsCompleted, then inspect its asset path, source/artifact digests, last-green fields, and diagnostics. Cancellation uses the standard CancellationToken; progress uses IProgress<OfflinePackageBuildProgress>. Invoke Build synchronously on the Unity Editor main thread; do not wrap it in Task.Run or run two Editors against the same project checkout.

Public surface index

The following groups account for the package's public top-level types. The first two groups are the ordinary integration contract. Serialized artifact and renderer-diagnostic groups are public so Unity can serialize assets or expose system telemetry; application code should not construct them.

Ordinary integration

Editor integration

Ordinary CharacterConversionDiscovery.Discover(prefab, preset) defaults to the prefab directory and <prefab filename>_EntityDesc.asset. A populated preset Output Root overrides the directory. It locates a moved published descriptor by Product Key; multiple matching _EntityDesc.asset entries are rejected rather than selecting one arbitrarily. Move it through Unity's AssetDatabase with its GUID intact. The explicit identity/root overload retains the legacy published basename.

OfflineBuildInput.PublishedAssetPath optionally selects a canonical .asset path under Assets; null/empty keeps RequestedOutputRoot/CharacterRuntimeAsset.asset. Original output roots still own immutable snapshots and Recovery; the published entry may be moved outside those roots. Do not change the original roots merely to relocate an entry.

Serialized package and asset contract

V6 retains product, source and artifact digests. It stores validated state write masks and fixed attachment transforms for LocalResolve. As in V5, there are no per-source receipts or serialized controller feature declarations; the reader checks actual semantic tables and execution capacities. CharacterRuntimeAsset.EditorInitialize computes and returns the artifact digest once. It no longer accepts a caller-computed digest or receipts. V4/V5 runtime loading is rejected. Rebuilding an existing owned V4/V5 output keeps the old asset and references until the V6 candidate passes validation; cancellation or publication failure preserves/restores the old file. The ArtifactV4 lineage directory name remains stable for Editor ownership/recovery; it does not select the payload reader.

New builds store lossless compiled animation bytes in CharacterRuntimeAsset.AnimationData, a CharacterAnimationData subasset named after the selected controller (ByteCount reports its binary size). Derived Mesh and Material subassets retain source object names. The published asset owns all three; runtime loading does not depend on ArtifactV4 snapshots. Textures and shaders remain ordinary external references. The legacy Payload field and its TextAsset loading API have been removed. AnimationData is required; external-payload assets must be rebuilt from their source Prefabs. The embedded animation bytes still use the V6 binary layout. Do not construct, rename, mutate or remove generated subassets; change sources and rebuild. User assets are not automatically migrated. The distributed Demos have been rebuilt with embedded data and source prefabs beside their descriptors in Resources; their EntityDesc loading keys are unchanged. Resources output roots keep Editor lineage/recovery under the corresponding Editor/ECSAnimatorGenerated directory. These snapshots are not runtime loading dependencies. Distributed samples omit local snapshots. To start rebuilding a sample in another project, use a renamed source prefab and a preset with a new unique Product Key; retain that project's new snapshots for subsequent rebuilds.

Advanced ECS and renderer diagnostics

CharacterRootTag, CharacterDiagnostic, CharacterUpdateBudget, CharacterLodSelection, CharacterOccurrenceA, CharacterAttachmentPose, CharacterEvaluationSystem, CharacterDynamicPackingSystem, CharacterDynamicGpuUploadSystem, CharacterStaticResidencySystem, CharacterEntitiesGraphicsPresentationSystem, CharacterGpuAbi, CharacterGpuRecoveryRequirement, CharacterGpuBufferLease, CharacterStaticBufferLease, CharacterStaticPayloadSet, CharacterStaticPayloadBuilder, and CharacterDrawSubmissionObservation are framework/diagnostic surfaces. They are not required for normal spawning, AI, movement, animation commands, or attachments.

CharacterEntitiesGraphicsPresentationSystem.TryGetCurrentDrawSubmission and TryValidateCurrentShaderPasses are on-demand, main-thread diagnostics. The first scans current render plans and reports logical submissions before view culling plus completed frame retirements; its draw/visible counts are not native GPU draw-call or pixel measurements. Do not poll it per character or use it instead of Profiler/GPU evidence for performance claims.

A character evaluation failure is terminal for that instance: its diagnostic is retained, animation updates stop, render children are hidden, and commands/observations reject it. Destroy and respawn the instance after correcting the cause. Other characters continue; failed events, attachment poses and staged frozen poses are never published. Internal mutable state is not restored for retry.

External RegisterConsumer(GraphicsFence) support has been removed. Buffer leases are diagnostic lifetime pins; external GPU submission through them is unsupported. The package renderer alone owns the completion protocol, using a queue-ordered generation marker readback after detachment. A GPU submission fault stops that World at the first fault and retains resources without proven completion; it no longer continues through spare ring slots. Inspect the reported error and rebuild the World. Fault-retained buffers are never forcibly disposed; normal shutdown still drains proofs.

ECSAnimator/Lit supports URP/HDRP 14 through pipeline-specific native passes. External opaque/cutout HLSL and Graph profiles remain Preview/NeedsVerification. See the Shader contract, pipeline setup and platform boundaries.

The optional Aim Idle example uses a separate four-second chest-level hold with breathing and continuous vertical arm IK. The original Attack demo is unchanged.