30 KiB
Project M — CLAUDE.md
Multiplayer game on Unity DOTS (Entities) + Netcode for Entities — server-authoritative, input-only clients, client prediction. This file is committed and is the authoritative, cross-machine source of conventions. The /dots-dev skill drives feature work; one-time stack setup lives in Docs/dots-setup-task.md.
Build-gotcha archive: the full, verbose per-milestone build lessons were condensed out of this file on 2026-06-04 (to stay under the 40 KB context-load limit). The distilled rules live below in Build gotchas (distilled); the long-form originals are in
Docs/Vault/_Meta/CLAUDE_Build_Gotchas_Archive.md, and the design rationale in the per-milestone DRs (Docs/Vault/07_Sessions/_Decisions/DR-###).
Stack — Unity 6.4.7 (6000.4.7f1, stable) as of 2026-05-30
| Package | Version | Notes |
|---|---|---|
com.unity.entities |
6.4.0 | Entities/Collections/Graphics track the Editor version (6.x). |
com.unity.entities.graphics |
6.4.0 | Renders entities under URP 17.4. |
com.unity.collections |
6.4.0 | (transitive) |
com.unity.netcode |
1.13.2 | Netcode for Entities (ECS). NOT com.unity.netcode.gameobjects. Independent 1.x line. |
com.unity.physics |
1.4.6 | Unity Physics (DOTS). Independent 1.x line. |
com.unity.charactercontroller |
1.4.2 | DOTS kinematic collide-and-slide. Declares entities/physics 1.3.15 but resolves on 6.4.0/1.4.6 via SemVer floor (no downgrade). |
com.unity.transport |
2.7.2 | (transitive) |
com.unity.burst |
1.8.29 | (transitive) |
com.unity.mathematics |
1.3.3 | (transitive) |
Values match packages-lock.json (reconciled 2026-06-02; URP 17.4.0, test-framework 1.6.0, ugui 2.0.0, multiplayer.center 1.0.1). History: briefly tried 6.6.0a6 (renumbers Netcode→6.6.0/Physics→6.5.0/Entities→6.5.0) but its Netcode/Transport runtime is a confirmed engine bug ("invalid wrapped network interface") → reverted. If returning to 6.6, expect the renumber + re-test runtime. See DR-002_Unity66_Alpha_Netcode_Transport and Docs/Vault/_Meta/CLAUDE_Build_Gotchas_Archive.md.
Namespaces & assembly split
Root namespace: ProjectM. Code lives under Assets/_Project/Scripts/ in four asmdefs (never create/edit .csproj/.sln; only .asmdef):
| Assembly | Namespace | Runs in | References |
|---|---|---|---|
ProjectM.Simulation |
ProjectM.Simulation |
client + server worlds | Entities, Unity.Transforms, Collections, Mathematics, Burst, Unity.Physics, Unity.NetCode |
ProjectM.Client |
ProjectM.Client |
client world only | + Simulation, Unity.Entities.Graphics, Unity.InputSystem, Unity.Transforms |
ProjectM.Server |
ProjectM.Server |
server world only | + Simulation, Unity.Transforms, Unity.NetCode |
ProjectM.Authoring |
ProjectM.Authoring |
bake time (+ scene runtime) | Simulation, Entities, Unity.Entities.Hybrid, Collections, Mathematics, Unity.NetCode |
- Simulation = components + systems shared by both worlds (most gameplay). Client/Server = world-specific. Authoring =
…AuthoringMonoBehaviours +Baker<T>. - Other folders:
Assets/_Project/Subscenes/(baked entity subscenes),Assets/_Project/Prefabs/,Assets/_Project/Tests/EditMode/.
Build gotchas (distilled)
Long-form originals + the milestone each came from: Docs/Vault/_Meta/CLAUDE_Build_Gotchas_Archive.md. The highest-recurrence hazards are flagged ★.
Assemblies, asmdefs & source-gen
Unity.Transformsmust be a DIRECT asmdef reference for any assembly whose source-gen'd systems touchLocalTransform/LocalToWorld— transitive visibility compiles hand-written code but the generator emits CS0246 in*.g.cs.- Authoring asmdefs need
Unity.Entities.Hybrid(Baker<T>) +Unity.Collections(baking source-gen). Never name a nested bakerBaker(shadowsBaker<T>) — useFooBaker. - Never name an
IComponentDataPlayerInputand don'tusing UnityEngine.InputSystem;in a file referencing such a component — collides with the managedUnityEngine.InputSystem.PlayerInput, generator bindsRefRW<…>to the class → misleading CS8377. Fully-qualify Input System types instead. - The generated Input Actions C# wrapper must live inside the consuming asmdef — set the importer's
wrapperCodePath(in.inputactions.meta) to e.g.Assets/_Project/Scripts/Client/Input/ProjectMInput.cs; the default location compiles intoAssembly-CSharpwhich asmdefs can't reference. No.inputactionsedit unless you intend a wrapper regen. IInputComponentDatarequires implementingFixedString512Bytes ToFixedString().
Burst hazards ★
- Cross-assembly generics + enums trip Burst internal compiler errors. Predicted-spawn classification (
SnapshotDataBufferComponentLookup.TryGetComponentDataFromSnapshotHistory<T>, takesref DynamicBuffer<SnapshotDataBuffer>in 1.13.2) and any enum compared inside a Bursted system are the known offenders. Make such systems plain non-BurstISystem, and store ops/schemes/region ids asbyte, neverenumin anything Bursted or in RPC payloads. - A Burst ICE corrupts the editor's incremental cache → afterward, valid
[BurstCompile]entry points log"… is not a known Burst entry point"+ run slow managed-fallback. A clean compile + green tests + working runtime confirm the code is fine. Fix = editor restart (or deleteLibrary/BurstCachewhile closed); a domain reload alone does NOT clear it. - Editing a Bursted ISystem's SystemAPI query set on an UNFOCUSED editor can leave a STALE binary → runtime
InvalidOperationException: "required component type was not declared in the EntityQuery"from an unrelatedGetSingleton<T>(Burst stack reports the OLD line number). Workaround: Burst compilation OFF for the session; permanent fix = restart. Prefer a focused editor for Burst-affecting edits.
Netcode / prediction ★
PredictedSimulationSystemGroupruns multiple times per frame on rollback → predicted systems must be deterministic/idempotent, filter with.WithAll<Simulate>(), and use no wall-clock /Time.deltaTime/System.Random.- Predicted physics is implicit — with the netcode-physics package present, Netcode relocates
PhysicsSystemGroupintoPredictedFixedStepSimulationSystemGroup(child of the predicted group, OrderFirst).NetCodePhysicsConfigonly tunes lag-comp/run-mode/history; put one in the gameplay subscene withPhysicGroupRunMode = LagCompensationEnabledOrAnyPhysicsEntities. - The predicted physics group is OrderFirst, so
[UpdateBefore/After(PredictedFixedStepSimulationSystemGroup)]from the parent predicted group sorts oddly:UpdateBeforeis ignored (1-tick offset, still in-sync); for same-tick, put the system inside the fixed-step group[UpdateBefore(PhysicsSystemGroup)].OrderFirst/OrderLastALSO wins againstUpdateBefore/Afterthe predicted group from the plainSimulationSystemGroup— a server-only system there always runs after the predicted group (use[UpdateAfter(PredictedSimulationSystemGroup)], neverUpdateBefore; Unity logs "Ignoring invalid UpdateBefore…"). - Move ownerless INTERPOLATED ghosts (enemies, pickups) SERVER-ONLY in the plain
SimulationSystemGroup— they aren't predicted; the server has no rollback. StockLocalTransformreplication carries position (no hand-written[GhostField]). A contactDamageEventappended there drains the following tick (~16ms, fine for melee). PhysicsVelocityauto-replicates (Netcode ships the default variant + serializer) — drive a predicted-physics body by writingPhysicsVelocity.Linear, not by teleportingLocalTransform.- Ownerless interpolated ghost ≠ owner-predicted for buffer replication. A server-spawned ownerless ghost replicates a
[GhostField] IBufferElementDatato all clients with noOwnerSendType/ noGhostOwner— server mutations just propagate.OwnerSendType.All+GhostOwnerare only for a predicting owner to recompute its own state. - One-off shared-state actions belong on an
IRpcCommand, not a predictedInputEvent(RPCs are reliable; one-shotInputEvents — likeFire— drop under server tick-batching). RPC payloads are plain blittable fields (no[GhostField]), scalars only (int CellX/CellZ, notint2). For a SINGLE shared target resolve a server singleton — never put anEntityin the command; use ghost-id+spawn-tick (SpawnedGhostEntityMap) only for many targets. - Apply server-only RPC effects in the server
SimulationSystemGroup, NOT the predicted loop (rollback would double-apply). Mutating aDynamicBufferis not a structural change, so it's safe while iterating a different query. - A system-ordering CYCLE is INVISIBLE to plain-Entities EditMode tests (they register systems individually, unsorted) — it only throws
ComponentSystemSorter"circular dependency cycle" at world creation (Play). When you add a system with cross-system[UpdateBefore/After], re-audit the EXISTING[Update*]attributes of the systems you order around (a newAfter(A)+Before(B)collided with B's pre-existingAfter(A)) and always Play-validate, not just EditMode. DR-017_Persistent_Base_Player_Driven_Pacing - A dev/debug
IRpcCommandwire TYPE must be UNCONDITIONAL (no#if) — the reflection-built RpcCollection hash must match across release/dev peers or the connection handshake refuses.#if UNITY_EDITOR-gate only the send/receive SYSTEMS + overlay, never the request struct. Re-mean bytes, don't rename: an enum/const whose byte VALUES are unchanged keeps the[GhostField]serializer identical → a global-loop reframe stays re-bake-free (only authoring default-value edits re-bake the subscene). - Derive enableable gates instead of replicating them. e.g. player
Dead= a LOCAL enableable derived every predicted tick from replicatedHealth<=0(rollback-correct on server + owner, no[GhostEnabledBit]). To write the bit on a disabled entity the query must visit it (.WithPresent<Dead>()); bake the enableable DISABLED so instances spawn off. Respawn/death timing is server-only. - Cooldown/spawn "next tick" sentinels: route every stored tick through
TickUtil.NonZero(...)(a computedServerTick+delaycan wrap to 0, the "ready" sentinel) and compare withNetworkTick.IsNewerThan/.TicksSince, never rawuint </ subtraction. GhostRelevancyfor region splits: useGhostRelevancyMode.SetIsIrrelevant(notSetIsRelevant) so untagged/global ghosts stay relevant for free — only enumerate cross-region ghosts to hide.RegionTag{byte Region}is server-only, NOT a[GhostField](server decides relevancy; client just gains/loses ghosts).RelevantGhostForConnection{int Connection (=NetworkId.Value); int Ghost (=GhostInstance.ghostId)}.- Shared GLOBAL state (cycle phase, resource ledger, goal meter) rides an UNTAGGED ghost, never a region-tagged one (
SetIsIrrelevantwould hide it cross-region). Resolve a ledger buffer via a DISTINCT tag (ResourceLedger), neverGetSingleton<StorageEntry>when a secondStorageEntrybuffer exists elsewhere → "multiple instances" throw.
Physics & character controller
- Unity Physics 1.x bakes built-in
UnityEnginecolliders +Rigidbody(the Physics-0.xPhysicsShapeAuthoring/PhysicsBodyAuthoringare gone). Static collider (no Rigidbody) → baked into the subscene PhysicsWorld, deterministic, no replication.Rigidbody.FreezeRotationis NOT honored by the baker — zero angular velocity + write rotation each tick, or setPhysicsMass.InverseInertia = float3.zero. - The player is a Unity Character Controller kinematic character (NOT a dynamic Rigidbody —
PlayerMoveSystem/PlayerPlanarConstraintSystemwere deleted; the DR-006 predicted-physics infra is kept).PlayerControlSystemmaps input →CharacterControl;CharacterProcessorcollide-and-slides in the relocatedKinematicCharacterPhysicsUpdateGroup. CC 1.4.2 API =IKinematicCharacterProcessor<T>+KinematicCharacterDataAccess+ staticKinematicCharacterUtilities.Update_*(verify shape withunity_reflect, don't assume the legacy aspect). KinematicCharacterUtilities.BakeCharacteraborts if the GameObject has aRigidbodyand needs uniform (1,1,1) scale.CharacterInterpolationmust be PredictedClient-only (register aDefaultVariantSystemBasestripping it from server + interpolated prefabs) — else double-interp on remotes. Do NOT copy the CC sample's globalLocalTransform → DontSerializeVariant(project-wide; breaks the non-character ghosts that rely on stockLocalTransformreplication).- Top-down CC config:
SnapToGround=false,InterpolateRotation=false(rotation owned byPlayerAimSystem),SimulateDynamicBody=false; gravity handled by feedingfloat3.zerotoUpdate_GroundPushing. - Hit/area tests must be SWEPT, not point checks — a point distance check tunnels through a target when the per-tick step exceeds the target radius (high speed or tick-batching). Test the segment traversed this tick. In a PLAIN
SimulationSystemGroupsystem do NOT useSystemAPI.Time.DeltaTime(it's the wall-frame delta, not the fixed step) — store the per-tick step on the projectile (Projectile.LastStep, written in the fixed-step group) and rebuild the segment ascur - dir*LastStep. A node hit by N projectiles in one tick:ecb.DestroyEntityat-most-once (destroyed-bitset; a double destroy throws at Playback). When TWO target types share one projectile pass (resource nodes + Blight clutter), UNIFY the sweep into one best-target loop + one shared destroyed-bitset — separate sweep systems eachDestroyEntitya projectile that overlaps both → double-destroy at Playback (DR-018). A float per-hit yield cast(int)that ALSO gates despawn is an immortal-sink footgun: a sub-1.0 value →(int)=0 → no deposit AND noRemainingdecrement, yet the shot is still consumed → an unkillable target that silently eats projectiles. Guard withmath.max(1,(int)yield)in the consumer and[Min(1f)]on the authoring (the node path had it; the clutter sibling didn't).
Build / structures / grid
- Build-grid math must be deterministic + integer-stable: corner-origin, center-returning, half-open cell bounds,
math.floor(not truncation — negatives). LockCellSize/PlotSizeas a coordinate space once (BaseGridMath, EditMode-tested) — changing them invalidates placed structures. PlacedStructure{[GhostField] byte Type; int2 Cell (server-only); uint NextTick; uint LastProcessedTick}on an ownerless interpolated ghost. Bake the two tick fields now (turret reusesNextTickas fire cooldown; they're the offline-catch-up linchpin). OnlyTypereplicates (client derivesCellviaBaseGridMath.WorldToCell). Data-drivenStructureCatalogbuffer. Occupancy is DERIVED by scanning live structure ghosts into a TempNativeHashSet<int2>, never a mutable buffer on the bakedBaseAnchor.- Co-op placement atomicity: commit the
StorageMath.Withdraw+ cell-reservation in-place inside the RPC foreach (onlyInstantiategoes through the ECB) so two same-tick requests for one cell can't both pass. - Buildable turret = hitscan = reversed
EnemyAISystem: nearest living Husk in-region within Range, onNextTickcooldown append a directDamageEvent{Damage, SourceNetworkId=-1}→ reusesHealthApplyDamageSystem. No projectile → no tunnelling, no team model. - Resource-gated ability tiers reuse
StatModifier— grow ONEStatModifier{Target=Damage, Op=PercentAdd, SourceId=<sentinel>}(replace-by-SourceId so the buffer stays bounded);StatRecomputeSystemfolds it intoEffectiveAbilityStatson both worlds.GoalProgress{[GhostField] int Charge, Target}lives on the global CycleDirector ghost. Disk-persistence deferred to post-M7 — freeze the save schema + bake structure tick fields now so it's additive.
Presentation / juice / VFX
- All juice/HUD = client-only managed
SystemBaseinPresentationSystemGroup(once/frame, no rollback double-fire) that OBSERVES replicated state, never mutates the sim. Read ECS viaSystemAPI.QueryinOnUpdate+EntityManager.CompleteDependencyBeforeRO<T>()— NOT a MonoBehaviourLateUpdate(job-safety throw).Entityis a stable client dict key for a ghost's lifetime — prune the cache each frame (a pruned enemy = a kill → death VFX); neverDestroyEntitya ghost from the client (GhostDespawnSystemowns despawn). Hit-stop = a camera punch, neverTime.timeScale(corrupts the deterministic sim). - Asset-free presentation: procedural
AudioClip.CreateSFX; runtimeParticleSystempool (Sprites/Default + HDR start color); code-built uGUI HUD (RawImageoverTexture2D.whiteTexture, legacyText+LegacyRuntime.ttf). Edit a prefab asset's component in code viaPrefabUtility.LoadPrefabContents→ modify →SaveAsPrefabAsset(root, path)→UnloadPrefabContents. Watch shared-material bleed when re-tinting. ACES tonemapping needs URP color grading mode = HDR (m_ColorGradingMode=1). - Prototype glue lives in
ProjectM.Clientas MonoBehaviours:PrototypeCameraRig(player-following ARPG cam),VFXConfig(staticInstance+ prefab fields bridging authored VFX to the managedCombatFeedbackSystem; keep a procedural fallback). A static presentation bridge must reset on play-enter via[RuntimeInitializeOnLoadMethod(SubsystemRegistration)](statics survive fast-enter-playmode reloads → stale flash).
Art import (HDRP store packs → URP)
- BefourStudios art is HDRP-authored → magenta under URP 17.4 + Entities Graphics. Convert, don't switch pipelines (HDRP breaks Entities Graphics). Re-author to stock URP/Lit via
Assets/_Project/Scripts/Editor/EnvArtTools.cs(menuProjectM/Art/1. Convert Curated Env Materials). Synty art is URP-native — no conversion. - A dark-lit screenshot MASKS material bugs — verify material values. Always
shader.GetPropertyType(idx)-guard beforeGetColor/GetFloat/GetTexture(S_General's_BaseColorMultiplyis a float;GetColoron it returns black). Gate source emission on the_Emissiveflag AND a fixture name. Keep converted env metallic low (0.1–0.2). VolumeProfile.Add<T>()does NOT persist (serializes{fileID:0}on save) — useAssetDatabase.AddObjectToAsset(component, profile)+SaveAssets, verify on disk.LocalTransform.FromPosition()resets Scale=1 — server spawners must read the prefab's bakedLocalTransformand override only Position (Scale is a replicated[GhostField]→ consistent-but-wrong).- Static decor → gameplay subscene (Entities Graphics renders only baked/EG-spawned entities); strip colliders from cosmetic props (else they bake into the PhysicsWorld the CC sweeps), no
GhostAuthoringon scenery. Cosmetic SampleScene GameObjects (classic URP,SyntyWorldroot) render via classic URP and their colliders are inert to the DOTS PhysicsWorld — no stripping needed there. To swap a subscene object's visual while keeping collision: disable the MeshRenderer, keep the collider. - A GA "projectile" prefab self-propels (non-kinematic
Rigidbody+ collider +ProjectileMoveScript) — strip to particles beforeStart(CombatFeedbackSystem.StripCosmetic). Verify a prefab's components, not its name.
Aim controls
- Client-derived aim rides the EXISTING
PlayerInput.Aim[GhostField]— mouse-cursor aim computed inPlayerInputGatherSystem(managedSystemBase,GhostInputSystemGroup):Mouse.current.position→Camera.main.ScreenPointToRay→AimMath.PlanarAimFromRay(pure, unit-tested) → player→cursor direction. Only the direction crosses the wire; strafe-while-aiming is free (Movealready decoupled fromAim). - Active scheme = last-meaningful-actuation-wins, replicated as
byte(PlayerInput.Scheme, KBM=0/Gamepad=1 — byte because compared in BurstedAbilityFireSystem). Server gates theAutoTargetcone to gamepad only → precise mouse, gamepad-only assist. - Cursor/reticle = client
PresentationSystemGroupSystemBase(AimReticleSystem) that OBSERVES. Re-raycast the KBM ground point INSIDE that system (PresentationSystemGroup runs after the follow-cam's LateUpdate) — latching from the gather drifts a frame behind. Hardware cursor hidden while aiming + focused, restored on focus-loss/OnDestroy.
MCP / editor workflow ★
- Edit Assets
.csONLY via MCPapply_text_edits/create_script(Unity's scripting pipeline) — the rawWritetool does NOT reliably trigger a recompile on an unfocused editor → tests/execute_coderun a stale assembly. (Write/Editare fine for non-asset files: this vault, asmdef JSON, etc.) apply_text_editswith MULTIPLE non-adjacent edits in one call can MISALIGN (a paired replace+delete hit the line above the target). One edit per call (or strict bottom-first), always withprecondition_sha256(it returns the current SHA on mismatch).create_scriptwon't overwrite an existing path; full-file rewrites = whole-spanapply_text_edits(its brace-balance validator guards botched spans) ormanage_script delete+create_script(NON-GUID-referenced files only — systems/tests, never authoring MonoBehaviours).script_apply_edits replace_methodis safe for class methods but still can't target astruct : ISystem(use whole-span). DR-017_Persistent_Base_Player_Driven_Pacingexecute_coderuns as a method body — nousingdirectives (parse as statements); fully-qualify every type. Identify worlds byworld.Name == "ServerWorld"/"ClientWorld"(flags overlap a sharedGamebit).manage_gameobject create/manage_prefabs modify_contentscomponent_propertiesSILENTLY DROP enum + Vector3 fields — set those via a follow-upmanage_components set_propertyand VERIFY throughmcpforunity://scene/gameobject/{id}/component/{Type}(or read the baked component inexecute_codeafter Play).manage_material set_renderer_coloruses a runtime PropertyBlock that does NOT persist into Play — create + assign a material asset instead.- New ghost prefab recipe:
manage_asset duplicatean existing correctly-configured ghost (e.g.UpgradePickup.prefab) →manage_prefabs modify_contentsto swap the authoring MonoBehaviour (strip MeshFilter+MeshRenderer for an invisible state-holder) — its ownerless/interpolatedGhostAuthoringComponent+LinkedEntityGroupAuthoringcome free. Runtime-spawn shared ghosts via a one-shot server spawner; don't bake them into the subscene (dodges the prespawn handshake). Wire a baked spawner into the subscene:manage_scene load additive→set_active_scene Gameplay→ create + set props + verify →save→set_active_scene SampleScene→close_scene(re-bakes on Play). - An UNFOCUSED editor throttles Edit mode to near-idle (MCP pings time out, bridge looks hung — it still queues;
telemetry_pingsucceeds) and stalls EditMode test INIT (passrun_tests(init_timeout=120000), retry).Application.runInBackgroundonly helps in Play mode. Don't pilerefresh_unityonto a blocked main thread; preferrefresh_unity scope=scriptsfor code-only changes. Ask the operator to focus Unity for heavy build/test/Burst sessions. - Run an adversarial design-review Workflow (netcode/relevancy · determinism/prediction · reuse/scope → synthesize) BEFORE coding a netcode-heavy slice — it has pre-caught relevancy traps, singleton collisions, dt-traps, double-destroys.
Bootstrap & worlds
ProjectM.Simulation.GameBootstrap : ClientServerBootstrapoverridesInitialize, setsAutoConnectPort = 7979(in-editor auto-connect over IPC), callsCreateDefaultClientServerWorlds(). Entering Play Mode createsServerWorld(WorldFlags.GameServer) +ClientWorld(WorldFlags.GameClient).Assets/_Project/Subscenes/Gameplay.unityis wired intoSampleScene(GameObjectGameplaySubScene) as a baking target. ReplaceSampleScenewith a dedicated bootstrap scene when building for real.- Region split: one server world; the expedition lives at
base + (1000,0,0), hidden per-connection viaGhostRelevancy(see the Netcode gotchas). Expedition place = cosmetic ground/pillars in SampleScene at the +1000 offset; gameplay nodes/gates are baked subscene entities. See DR-013_M6_Aether_Cycle_Region_Split.
DOTS / ECS conventions (authoritative summary)
Full rules: ~/.claude/skills/dots-dev/references/dots-conventions.md (Windows: %USERPROFILE%\.claude\skills\dots-dev\references\). These replace classic MonoBehaviour/GameObject patterns.
struct : IComponentDatais the default (unmanaged, Burst/job-friendly).class : IComponentDataonly for genuine managed refs (main-thread, no Burst).IBufferElementDatafor per-entity arrays.IEnableableComponentto toggle state without a structural change.- Systems:
ISystem(struct) +[BurstCompile]is the default;SystemBaseonly when touching managed objects.SystemAPI.Query<…>()to iterate. Aspects (IAspect) are DEPRECATED (Entities 1.4+) — do not author new ones.Entities.ForEachis legacy. - Jobs:
IJobEntity/IJobChunk; threadJobHandlethroughstate.Dependency; mark inputs[ReadOnly]. Allocators:Temp(frame),TempJob(one job),Persistent(must dispose). Burst breaks on managed types/exceptions/reflection/strings. - Structural changes (add/remove component, create/destroy entity) invalidate handles + cause sync points → batch via
EntityCommandBuffer(Begin/EndSimulationEntityCommandBufferSystem;.AsParallelWriter()in parallel jobs). - Baking:
…AuthoringMonoBehaviour +class FooBaker : Baker<FooAuthoring>→GetEntity(authoring, TransformUsageFlags.…)thenAddComponent. Subscenes stream async — entities aren't present the instant a reference exists. - Netcode: ghosts = replicated entities (
GhostAuthoringComponent+[GhostField]); predicted (player-controlled, rolled back) vs interpolated. Core sim runs inPredictedSimulationSystemGroup(fixed step, runs multiple times per frame on rollback → deterministic/idempotent; filter with.WithAll<Simulate>()). Server-authoritative: clients send input (IInputComponentData), not state. RPCs (IRpcCommand) for one-off events. No wall-clock/Time.deltaTime/System.Randomin predicted sim. - Always verify volatile DOTS/Netcode API shape via context7 at code-time — do not trust memory. Pinned IDs: Entities →
/websites/unity3d_packages_com_unity_entities_6_5_manual; Netcode →/websites/unity3d_packages_com_unity_netcode_1_10_api(closest published; we run 1.13.2 — re-resolve if a 1.13 set appears); ECS samples →/unity-technologies/entitycomponentsystemsamples.
Testing
- Default = plain-Entities EditMode test: create a
World, register the system inSimulationSystemGroup, tick, assert. Public API, version-independent. Example:Assets/_Project/Tests/EditMode/HeartbeatSystemTests.cs. Run viarun_tests(mode="EditMode", assembly_names=["ProjectM.Tests.EditMode"]). NetCodeTestWorldisinternalin netcode 1.13.2, exposed only to a fixed[InternalsVisibleTo]allow-list — to use it, name a test asmdef to match an entry (e.g.Unity.NetcodeSamples.EditModeTests) or vendor the test utils. Netcode world boot is covered by the Play Mode check, not a NetCodeTestWorld test. See DR-001_Netcode_Test_Harness.- Burst/source-gen errors surface at editor compile, not a plain build — always
read_consoleafter script changes, and run a play/tick test, not just a compile. Cover swept hit-detection with a tunnelling regression test (the point-check tunnel bug doesn't surface in a point-based unit test).
Guardrails
- Never edit a
.metaindependently of its asset; delete an asset and its.metatogether. - Never read/write
Library/,Temp/,obj/,Logs/,UserSettings/(generated/cache). Use MCP resources for editor state. - Never create/edit/commit
.csproj/.sln— only.asmdef. - No asset/scene edits during Play Mode. Check
editor_state.advice.ready_for_toolsbefore mutating; package adds/refreshes trigger domain reloads — wait foris_compiling=false.
Memory — four layers (which tool when)
| Layer | Use for | Crosses machines? |
|---|---|---|
In-repo vault Docs/Vault/ |
Design docs, decision records (DR-###), session logs, roadmap — human-facing truth | Yes (git) |
| basic-memory MCP | Semantic/wikilink recall over those vault files | Yes (indexes the vault) |
| serena MCP | C# symbol nav (find_symbol, references) of Assets/_Project/ |
N/A (from code) |
Native Claude memory (memory/, MEMORY.md) |
Machine-local facts, working-style, preferences | No |
- Where is X / who calls it → serena (fallback
Grep/Glob). What did we decide / how does Z work → basic-memory → read the vault note. Literal string / asset GUID → Grep/Glob. Current DOTS API → context7. Conventions → this file. Long-form build lessons →Docs/Vault/_Meta/CLAUDE_Build_Gotchas_Archive.md. - Cross-machine rule: durable truth goes in the vault or this file (both committed). Native
memory/is local-only and does NOT sync — never the sole home of a decision. - serena C# caveat: its language server is flaky on Unity. If
find_symbolerrors/stalls, fall back toGlob/Grep.
Per-machine setup (NOT in git — redo on each machine)
.mcp.json is committed and portable (${CLAUDE_PROJECT_DIR} only). The dots-dev skill travels with the repo at .claude/skills/dots-dev/ (auto-discovered on clone). Each machine still needs:
uv/uvx, the Obsidian app +obsidian-cli. (Theunity-mcp-skilland nativememory/notes are machine-local and do not sync.)- basic-memory project registration:
uvx basic-memory project add gamevault "<repo>/Docs/Vault" --default, thenuvx basic-memory reindex --full --search --embeddings --project gamevault. - Unity 6.4 opens the project and the CoplayDev Unity-MCP bridge connects (
mcpforunity://editor/state→ready_for_tools).