AGENT SKILL

isystem-burst-compile

Implement a system as an unmanaged struct with Burst-compiled entry points to eliminate managed dispatch overhead and enable native code generation on the hot update path.

License 许可
MIT
最近更新
2026-07-25
Stars
★ 8
Forks
0

01 前言 Front Matter

name
isystem-burst-compile
tags
[ "core", "systems", "burst" ]
metadata
{ "tier": 3, "internal-only": true }
description
Implement a system as an unmanaged struct with Burst-compiled entry points to eliminate managed dispatch overhead and enable native code generation on the hot update path.

03 SKILL.md 正文

ISystem with BurstCompile

Intent

Implement a system as an unmanaged struct with Burst-compiled entry points to eliminate managed dispatch overhead and enable native code generation on the hot update path.

Use When

Any new system that does not require managed types (MonoBehaviour references, strings, class components). This is the default system type in Entities 1.x.

Avoid When

The system must access managed components, drive MonoBehaviour/GameObject state, or interoperate with managed Unity APIs. Use SystemBase only in those cases.

Senior Pattern

  • public partial struct MySystem : ISystem — partial required for source generation.
  • [BurstCompile] on OnCreate, OnUpdate, OnDestroy.
  • All ECS access via ref SystemState state parameter.
  • Persistent frame-to-frame state stored as struct fields (e.g., cached EntityQuery, counter).
  • No managed fields anywhere in the struct.

Code Template

[BurstCompile]
[UpdateInGroup(typeof(SimulationSystemGroup))]
public partial struct MovementSystem : ISystem
{
    private EntityQuery m_MovingQuery;

    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {
        m_MovingQuery = SystemAPI.QueryBuilder()
            .WithAll<Velocity, LocalTransform>()
            .Build();
        state.RequireForUpdate(m_MovingQuery);
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        float dt = SystemAPI.Time.DeltaTime;
        foreach (var (transform, vel) in
            SystemAPI.Query<RefRW<LocalTransform>, RefRO<Velocity>>())
        {
            transform.ValueRW.Position += vel.ValueRO.Value * dt;
        }
    }

    [BurstCompile]
    public void OnDestroy(ref SystemState state) { }
}

Anti-Patterns

  • Storing a managed reference (List<T>, string, class instance) as a struct field — compile error.
  • Calling Debug.Log, Object.FindObjectOfType, or any managed API inside a [BurstCompile] method — silently falls back to managed execution for that call site.
  • Treating ISystem as a class with inheritance — it is a value type; no virtual dispatch, no base class.
  • Calling state.EntityManager.CompleteAllTrackedJobs() as a workaround instead of properly chaining state.Dependency.

Runtime Risks

  • Non-Burst-safe call inside [BurstCompile] method: Burst silently removes the [BurstCompile] guarantee for that code path.
  • Mutable struct fields shared across two copies of the system struct: divergence if the ECS runtime moves the struct.

Performance Notes

Struct system = zero heap allocation for system state. Burst entry points eliminate JIT overhead. Prefer over SystemBase for all simulation code.

Architecture Guidance

Systems are stateless by default. Add struct fields only for cached queries and counters — not for gameplay state (that belongs on components).

04 同仓库更多 Skills

dyCuong03
dyCuong03/unity-agent-team

dots-update-groups

How to choose the right ECS system group and ordering so per-frame and per-fixed-step work is deterministic and never races its own readers. Covers InitializationSystemGroup / SimulationSystemGroup / PresentationSystemGroup / FixedStepSimulationSystemGroup / VariableRateSimulationSystemGroup, UpdateBefore / UpdateAfter peer ordering, OrderFirst / OrderLast group-boundary placement, RateManager, and the cross-group ordering trap. Use when adding an ISystem, fixing "value visible one frame late" bugs, or coupling simulation to a fixed timestep.

★ 8
dyCuong03
dyCuong03/unity-agent-team

dots-transform-patterns

The Entities 1.x transform model — LocalTransform (writable input) vs LocalToWorld (system-owned matrix), Parent/Child hierarchy, reparenting cost, uniform vs non-uniform scale (PostTransformMatrix), and when to opt out with custom transform systems. Use when designing parent/child hierarchies, runtime reparenting (mount/dismount/socket), or choosing transform components at the Baker boundary.

★ 8
dyCuong03
dyCuong03/unity-agent-team

dots-singleton-patterns

Model cross-system shared configuration and game state as a single-entity component with a strict single-writer contract. Covers RequireForUpdate gating, SystemAPI.GetSingleton / GetSingletonRW / HasSingleton / TryGetSingleton, bake-time vs runtime-created vs ECB-system singletons, the "exactly one entity" runtime invariant, and the single-writer rule. Use when designing frame-stable global config, shared mutable state, or any component intended to exist on exactly one entity.

★ 8
dyCuong03
dyCuong03/unity-agent-team

dots-hybrid-bridge

The one-way bridge between DOTS-owned runtime state and Unity-owned presentation. Covers UnityObjectRef for managed asset refs in components, the DOTS-writes / Unity-reads ownership rule, when to use managed IComponentData vs UnityObjectRef vs CompanionComponent, baker-bridge vs runtime-bridge, and SubScene boundary rules. Use when an entity must reference Unity assets (Mesh, Material, AudioClip, ScriptableObject), a MonoBehaviour view must read entity state, or input/UI must trigger ECS work.

★ 8
dyCuong03
dyCuong03/unity-agent-team

dots-event-driven-ecs

Model one-frame events and external requests in ECS without dual ownership, polling, or persistent state leaks. Covers request-tag pattern with ECB, enableable command components (no structural change), event buffers (IBufferElementData), explicit consumer ownership, one-frame latency rules, and the banned C# event / UnityEvent / static bus anti-patterns. Use when input/UI/network must trigger ECS work, when a one-frame signal fans out to N consumers (damage, hit, collision), or when state changes must be processed exactly once.

★ 8
dyCuong03
dyCuong03/unity-agent-team

valid_skill

A complete, well-formed test fixture skill for SkillHub validation testing. Covers basic task routing and code review for Unity projects.

★ 8