AGENT SKILL

wave8-wrong-system-group-fixed-timestep

Identify and fix the failure mode of placing fixed-timestep physics or simulation logic in the wrong system group, causing frame-rate-dependent execution instead of fixed-rate execution.

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

01 前言 Front Matter

name
wave8-wrong-system-group-fixed-timestep
tags
[ "systems", "antipattern", "debug" ]
metadata
{ "tier": 3, "internal-only": true }
description
Identify and fix the failure mode of placing fixed-timestep physics or simulation logic in the wrong system group, causing frame-rate-dependent execution instead of fixed-rate execution.

03 SKILL.md 正文

Wrong System Group — Fixed Timestep Failure Mode

Intent

Identify and fix the failure mode of placing fixed-timestep physics or simulation logic in the wrong system group, causing frame-rate-dependent execution instead of fixed-rate execution.

Use When

  • Diagnosing why physics behavior is frame-rate dependent or non-deterministic
  • Code review of any system that writes PhysicsVelocity, applies forces, or handles collision response

Avoid When

  • The system intentionally runs every rendered frame — SimulationSystemGroup or PresentationSystemGroup are correct for those cases

Senior Pattern

// WRONG — runs every rendered frame, not at fixed timestep:
[UpdateInGroup(typeof(SimulationSystemGroup))]
public partial struct PhysicsResponseSystem : ISystem
{
    public void OnUpdate(ref SystemState state)
    {
        // Applies forces — frame-rate dependent, non-deterministic physics
    }
}

// CORRECT — runs at fixed timestep (default 50Hz):
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
[UpdateBefore(typeof(PhysicsSystemGroup))]
[BurstCompile]
public partial struct PhysicsResponseSystem : ISystem
{
    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        // Applies forces — deterministic, fixed-rate
    }
}

// CORRECT — set custom fixed rate once at initialization:
[UpdateInGroup(typeof(InitializationSystemGroup))]
public partial class FixedRateBootstrapSystem : SystemBase
{
    protected override void OnCreate()
    {
        World.GetExistingSystemManaged<FixedStepSimulationSystemGroup>().Timestep = 1f / 30f;
        Enabled = false;  // run once
    }
    protected override void OnUpdate() { }
}

Diagnosis Checklist

  • System writes PhysicsVelocity or PhysicsMass → must be in FixedStepSimulationSystemGroup
  • System reads PhysicsWorldSingleton for queries → can be in SimulationSystemGroup (after physics completes)
  • System handles collision/trigger events → must be in FixedStepSimulationSystemGroup [UpdateAfter(PhysicsSimulationGroup)]
  • System interpolates for rendering → must be in PresentationSystemGroup

Anti-Patterns

  • Using SimulationSystemGroup for physics force application — frame-rate dependent results; diverges between 30fps debug and 120fps release.
  • Placing collision response in PresentationSystemGroup — runs after rendering, one frame late.
  • Setting FixedStepSimulationSystemGroup.Timestep every frame in OnUpdate — must be set once at initialization; per-frame mutation disrupts the accumulator.
  • Combining physics-rate logic and render-rate logic in the same system — run rates diverge; shared state is torn.

Runtime Risks

  • Systems in the wrong group cause non-deterministic physics, collision tunneling at low frame rates, and gameplay that diverges between debug (low FPS) and release (high FPS) builds.
  • FixedStepSimulationSystemGroup may execute 0, 1, or multiple times per rendered frame — systems inside it must not assume single-execution-per-rendered-frame.

Performance Notes

  • Default fixed rate: 50 Hz (0.02s). At 60 FPS render rate, the group runs once most frames and twice occasionally (catch-up).
  • Profile FixedStepSimulationSystemGroup independently from SimulationSystemGroup — frame spikes here often indicate physics world rebuild cost from structural changes.

Architecture Guidance

  • Force application + physics write: FixedStepSimulationSystemGroup [UpdateBefore(PhysicsSystemGroup)].
  • Physics event processing: FixedStepSimulationSystemGroup [UpdateAfter(PhysicsSimulationGroup)].
  • Spatial queries against built world: SimulationSystemGroup.
  • Visual interpolation / rendering sync: PresentationSystemGroup.

Related Skills

[[wave5-fixed-step-simulation-system-group]], [[fixed-step-simulation]], [[wave5-physics-velocity-force-application]], [[wave8-ecb-system-group-mismatch]]

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