AGENT SKILL

wave7-unity-disable-managed-components-guard

Conditionally compile out all managed IComponentData usage when building for platforms or configurations that prohibit managed components (IL2CPP strict, DOTS Runtime, or custom stripped builds).

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

01 前言 Front Matter

name
wave7-unity-disable-managed-components-guard
tags
[ "hybrid", "managed" ]
metadata
{ "tier": 3, "internal-only": true }
description
Conditionally compile out all managed IComponentData usage when building for platforms or configurations that prohibit managed components (IL2CPP strict, DOTS Runtime, or custom stripped builds).

03 SKILL.md 正文

UNITY_DISABLE_MANAGED_COMPONENTS Guard

Intent

Conditionally compile out all managed IComponentData usage when building for platforms or configurations that prohibit managed components (IL2CPP strict, DOTS Runtime, or custom stripped builds).

Use When

  • The project must support both managed-component and managed-component-free build targets
  • A platform or build configuration defines UNITY_DISABLE_MANAGED_COMPONENTS

Avoid When

  • The project targets only the standard Unity player — the guard adds complexity without benefit
  • All builds will always support managed components — unnecessary conditional complexity

Senior Pattern

// Managed component and its system — guarded:
#if !UNITY_DISABLE_MANAGED_COMPONENTS

public class RenderDataManaged : IComponentData
{
    public Material OverrideMaterial;
}

[UpdateInGroup(typeof(PresentationSystemGroup))]
public partial class ManagedRenderSystem : SystemBase
{
    protected override void OnUpdate()
    {
        foreach (var data in SystemAPI.Query<RenderDataManaged>())
        {
            // apply override material
        }
    }
}

#endif

// Blittable fallback — always present in ALL build configurations:
public struct RenderDataBlittable : IComponentData
{
    public int MaterialIndex;  // index into a shared material array
}

// Systems consuming blittable data — no guard needed:
[BurstCompile]
public partial struct RenderCategoryJob : IJobEntity
{
    [BurstCompile]
    public void Execute(in RenderDataBlittable data, ref RenderTag tag)
    {
        tag.MaterialIndex = data.MaterialIndex;
    }
}

Anti-Patterns

  • Leaving managed component code unguarded in a project that enables UNITY_DISABLE_MANAGED_COMPONENTS — compile error at build time, not runtime.
  • Guarding only the component definition but not the systems that use it — partial compile failure; system references undefined type.
  • Using the guard as an excuse to defer designing a blittable alternative — always provide a blittable fallback; the guard is an opt-in overlay, not a design deferral.
  • Nesting guards inconsistently (#if in one file, #endif in another) — C# requires matched pairs per file.

Runtime Risks

  • If a preprocessor guard is missing on a newly added system that references the managed component, the build fails at compile time — not runtime. Risk is missed guards in new code.
  • Guard absence is not detectable at runtime — enforce via build pipeline (CI build with UNITY_DISABLE_MANAGED_COMPONENTS defined).

Performance Notes

  • No runtime cost — compile-time only.
  • The blittable fallback struct is the hot-path data model in all configurations.
  • Managed overlay under the guard is the low-frequency presentation layer.

Architecture Guidance

  • Define blittable struct components as the primary data model — these are the performance-critical ECS data.
  • Use managed components as an opt-in overlay under the guard — presentation/rendering quality features.
  • Document which systems require the guard to be unset in a project-level comment or README.
  • Add a CI build target with UNITY_DISABLE_MANAGED_COMPONENTS defined to catch missing guards early.

Related Skills

[[managed-component-bridge]], [[wave7-system-api-managed-api-query]], [[icomponentdata-value-component]], [[world-system-filter]]

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