wave8-dynamic-buffer-invalidation

Prevent unsafe DynamicBuffer reference access after structural changes in DOTS/ECS systems.

6|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/dyCuong03/unity-agent-team --skill wave8-dynamic-buffer-invalidation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: wave8-dynamic-buffer-invalidation
Source: https://github.com/dyCuong03/unity-agent-team/tree/main/.claude/skills/unity-dots/wave8-dynamic-buffer-invalidation
Command: npx skills add https://github.com/dyCuong03/unity-agent-team --skill wave8-dynamic-buffer-invalidation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents undefined behavior, crashes, and silent corruption caused by reading a DynamicBuffer reference after a structural change invalidates its underlying memory pointer.

Core Features & Use Cases

  • Frame- and structural-change-safe access: Treats DynamicBuffer references as only valid within the current structural-change context.
  • Correct read-before-write ordering: Ensures buffer contents are read before performing operations like AddComponent, RemoveComponent, DestroyEntity, or CreateEntity.
  • Safe structural change handling: Uses EntityCommandBuffer (ECB) to defer structural changes until after reads complete, or explicitly re-fetches the buffer after changes.

Quick Start

Use the DynamicBuffer invalidation guidance when you call GetBuffer<T> and later perform any structural change in the same system update, by reading buffer contents first (or deferring structural changes with ECB) and never using the old buffer reference afterward.

Frequently Asked Questions about wave8-dynamic-buffer-invalidation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does my Unity DOTS DynamicBuffer reference cause a crash after structural changes?

A DynamicBuffer reference crashes after structural changes because Unity DOTS invalidates the underlying chunk memory pointer. Operations like AddComponent, RemoveComponent, or DestroyEntity move data, making the old buffer reference unsafe to read.

How do I safely read a DynamicBuffer before adding or removing components in the same frame?

To safely read a DynamicBuffer before structural changes, read all required buffer contents first before calling AddComponent or RemoveComponent. Treat buffer references as frame-scoped and never use the old reference after the mutation occurs.

Can I use EntityCommandBuffer to defer structural changes and keep DynamicBuffer access safe?

Yes, using EntityCommandBuffer to defer structural changes keeps DynamicBuffer access safe. By delaying AddComponent or DestroyEntity operations until ECB playback, you ensure buffer reads complete before the underlying chunk memory is invalidated.

When do I need to re-fetch a DynamicBuffer in Unity ECS?

You need to re-fetch a DynamicBuffer in Unity ECS after any structural mutation occurs in the same system update. If you perform CreateEntity or DestroyEntity and still need buffer data, explicitly get the buffer again to retrieve a valid memory pointer.

What is the correct ordering for DynamicBuffer reads and structural changes in DOTS?

The correct ordering for DynamicBuffer reads and structural changes requires reading buffer data before executing mutations. Always perform buffer reads first, then apply structural changes, or defer them via EntityCommandBuffer to prevent undefined behavior.