Class AgentManagedStorage

Package

Storage for per-agent data that requires managed types.

The Unity ECS wants component data to be unmanaged, but an agent needs to keep hold of things that cannot be: its current path, a traversal provider, user callbacks. Historically these lived in class-based IComponentData components, but those are being removed from the Entities package.

Instead each agent owns one slot in a flat array here, and refers to it through an AgentManagedRef component holding nothing but an integer.

# Threading

Reads take a single snapshot of entries and index it. Growth allocates a larger array, copies, and publishes the new reference, so a reader racing with growth keeps using the pre-growth array; that array stays alive and every slot it already contained still holds the right data.

Invariant: every write to an entry goes through one of the locked methods here, never through a snapshot the caller is holding. Growth copies entry payloads rather than aliasing them, so a write through a snapshot that growth has already superseded lands in an array nobody reads any more and is silently lost. Taking the lock re-reads entries, which is what makes a write always land in the live array.

Inner Types

All managed data for a single agent.

Private/Protected Members

Allocate (owner, state, settings)

Allocates a slot for a newly created agent.

Takes a slot off the free list, growing entries if the list is empty.

CloneFrom (sourceSlot, newOwner)

Gives a cloned agent its own copy of the managed data it currently shares with sourceSlot.

DestroyAgent (entityManager, entity)

Destroys an agent entity, releasing its managed data first so that it dies immediately.

Free (slot, expectedOwner)

Releases a slot and disposes the data in it.

GetChecked (slot, owner)

Returns the entry belonging to owner.

Explains the one mistake that can produce a slot which does not belong to its entity.

SetAfterControl (slot, owner, value)
SetBeforeControl (slot, owner, value)
SetBeforeMovement (slot, owner, value)
SetLinkTraversal (slot, owner, value)
SetSettings (slot, owner, value)
TryGet (slot, owner, entry)

Reads the entry belonging to owner without throwing.

entries

Slot storage.

Internal Static
freeSlotCount
Private Static
freeSlots

Slots that have been freed and can be handed out again.

Private Static
mutateLock

Guards allocation and release.

Private Static Readonly
usedSlots

Number of slots in entries that have ever been handed out.

Private Static