AGENT SKILL

wave7-ecs-to-go-transform-sync

Synchronize ECS entity world-space position/rotation to a companion GameObject''s Transform each frame for hybrid rendering or audio.

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

01 前言 Front Matter

name
wave7-ecs-to-go-transform-sync
tags
[ "hybrid", "transforms" ]
metadata
{ "tier": 3, "internal-only": true }
description
Synchronize ECS entity world-space position/rotation to a companion GameObject''s Transform each frame for hybrid rendering or audio.

03 SKILL.md 正文

ECS-to-GO Transform Sync

Intent

Synchronize ECS entity world-space position/rotation to a companion GameObject's Transform each frame for hybrid rendering or audio.

Use When

  • A companion GO (VFX particle system, audio source, UI widget) must track an ECS entity's world-space position without full ECS rendering
  • Hybrid mode where some entities use GO rendering alongside ECS simulation

Avoid When

  • The entity is rendered via Entities Graphics — LocalToWorld is consumed directly; no GO sync needed
  • Entity count exceeds ~500 synced GOs — main-thread bottleneck; consider instanced rendering instead

Senior Pattern

[UpdateInGroup(typeof(PresentationSystemGroup))]
public partial class CompanionTransformSyncSystem : SystemBase
{
    protected override void OnUpdate()
    {
        foreach (var (l2w, go) in
            SystemAPI.Query<RefRO<LocalToWorld>, UnityEngine.GameObject>())
        {
            if (go == null) continue;  // guard against externally destroyed GOs

            // SetPositionAndRotation is one native call — faster than separate .position/.rotation:
            go.transform.SetPositionAndRotation(
                l2w.ValueRO.Position,
                l2w.ValueRO.Rotation);
        }
    }
}

Anti-Patterns

  • Syncing Transform.position inside a job — Transform is a managed type; jobs cannot access it.
  • Reading LocalTransform instead of LocalToWorld for world-space sync — LocalTransform is local-space; wrong for child entities in a hierarchy.
  • Syncing in SimulationSystemGroup — GO Transform state is not simulation input; sync must run after simulation completes in PresentationSystemGroup.
  • Syncing every frame at high entity counts (>500) without LOD or distance culling — main-thread bottleneck; profile explicitly.
  • Omitting null guard — GO destroyed externally produces MissingReferenceException every frame.

Runtime Risks

  • If the GO is destroyed externally (scene unload, Object.Destroy), the managed reference becomes null — null guard required.
  • Transform sync reads LocalToWorld which is written by TransformSystemGroup — PresentationSystemGroup runs after TransformSystemGroup, so values are current-frame.

Performance Notes

  • Transform.SetPositionAndRotation is faster than separate .position + .rotation assignments — one native P/Invoke call.
  • Still main-thread only. Profile at >200 synced entities. At >500, consider:
    • Distance-based culling (only sync entities within camera range)
    • Replacing companion GOs with GPU instancing

Architecture Guidance

  • Run exclusively in PresentationSystemGroup (after simulation and TransformSystemGroup).
  • Never sync in SimulationSystemGroup or FixedStepSimulationSystemGroup — GO Transform state is not simulation input.
  • Companion GO Transform is write-only from ECS perspective — never read GO Transform.position back into ECS.

Related Skills

[[wave7-companion-go-lifecycle]], [[wave7-add-component-object-hybrid-attach]], [[local-to-world-read-only-contract]], [[wave7-system-api-managed-api-query]]

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