Class ScyllaLooseOctree<T>
Typed wrapper around ScyllaLooseOctree that associates a payload of type
T with each item ID while keeping all spatial partitioning Burst-friendly.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaLooseOctree<T> : IScyllaCollection, IDisposable
Type Parameters
| Name | Description |
|---|---|
| T | The managed payload type to associate with each item. Any reference or value type is supported; payloads are stored in a managed Dictionary<TKey, TValue> and are not accessible from Burst-compiled jobs. |
Remarks
The spatial tree (Tree) stores only integer IDs and AABBs and is fully Burst-compatible. The payload dictionary is managed code and must be accessed on the main thread or a non-Burst thread.
Queries return item IDs via a Unity.Collections.NativeList<T>; use TryGetPayload(int, out T) to resolve each ID to its associated payload after a query completes.
This class intentionally does not implement IScyllaCollection<T> because the octree's primary API is ID+bounds-based, not element-based enqueue/dequeue semantics.
Constructors
ScyllaLooseOctree(ScyllaAABB3, int, int, float, Allocator, int)
Initializes a new ScyllaLooseOctree<T> with spatial partitioning and typed payload storage.
Declaration
public ScyllaLooseOctree(ScyllaAABB3 rootBounds, int maxDepth, int maxItemsPerNode, float looseness, Allocator allocator, int initialItemCapacity = 64)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaAABB3 | rootBounds | Tight root bounds of the octree. |
| int | maxDepth | Maximum subdivision depth (0 disables subdivision). |
| int | maxItemsPerNode | Maximum items per node before subdivision. |
| float | looseness | Looseness factor ( |
| Allocator | allocator | Memory allocator for internal native containers. |
| int | initialItemCapacity | Initial capacity hint for both the item map and payload dictionary. |
Remarks
Internally creates a ScyllaLooseOctree for ID/bounds management and a Dictionary<TKey, TValue> for payload lookup. All spatial parameters are forwarded unchanged to the underlying octree; see ScyllaLooseOctree(ScyllaAABB3, int, int, float, Allocator, int) for parameter documentation and validation rules.
Properties
Capabilities
Capability flags supported by this collection instance.
Declaration
public ScyllaCollectionCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionCapabilities |
Count
Number of items currently stored.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
Convenience property indicating whether the tree contains no items.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
SyncRoot
Synchronization root for externally coordinating operations with this collection.
Declaration
public object SyncRoot { get; }
Property Value
| Type | Description |
|---|---|
| object |
ThreadSafety
Declares the thread-safety guarantees provided by this collection instance.
Declaration
public ScyllaCollectionThreadSafety ThreadSafety { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionThreadSafety |
Tree
Gets the underlying ID-only tree.
Declaration
public ScyllaLooseOctree Tree { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaLooseOctree |
Methods
Add(int, T, ScyllaAABB3)
Inserts a new item with spatial bounds and an associated typed payload.
Declaration
public void Add(int itemID, T payload, ScyllaAABB3 bounds)
Parameters
| Type | Name | Description |
|---|---|---|
| int | itemID | Unique identifier for the item. Must not already be present in the tree. |
| T | payload | The typed payload to associate with this item ID. |
| ScyllaAABB3 | bounds | Spatial bounds of the item. Must be fully contained by the root loose bounds. |
Remarks
Inserts the item into the underlying ScyllaLooseOctree via its
Add(int, ScyllaAABB3) method (which throws on duplicate IDs or out-of-bounds),
then stores payload in _payloadByID. If the key already
exists in the payload dictionary, the payload is overwritten.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
| InvalidOperationException | Thrown when an item with |
Clear()
Removes all items from the tree and clears payload storage.
Declaration
public void Clear()
Dispose()
Disposes the underlying ScyllaLooseOctree and clears the payload dictionary.
Declaration
public void Dispose()
Remarks
Clearing the payload dictionary releases references to managed payload objects so the GC can reclaim them. The underlying octree's native containers are released via Dispose(), which is idempotent.
QueryOverlap(ScyllaAABB3, NativeList<int>)
AABB overlap query: appends the IDs of all items whose stored bounds overlap query.
Declaration
public void QueryOverlap(ScyllaAABB3 query, NativeList<int> results)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaAABB3 | query | The axis-aligned bounding box to test against all stored items. |
| NativeList<int> | results | Native list that receives matching item IDs. Existing entries are preserved; matches are appended to the end. |
Remarks
Results are appended to results - the list is not cleared before the query.
Use TryGetPayload(int, out T) to resolve item IDs to their associated typed payloads.
QueryRadius(float3, float, NativeList<int>)
Sphere query: appends the IDs of all items whose stored bounds intersect the sphere
defined by center and radius.
Declaration
public void QueryRadius(float3 center, float radius, NativeList<int> results)
Parameters
| Type | Name | Description |
|---|---|---|
| float3 | center | World-space center of the query sphere. |
| float | radius | Radius of the query sphere in world units. Negative values produce no results. |
| NativeList<int> | results | Native list that receives matching item IDs. Existing entries are preserved; matches are appended to the end. |
Remarks
Results are appended to results - the list is not cleared before the query.
Use TryGetPayload(int, out T) to resolve item IDs to their associated typed payloads.
Remove(int)
Removes an item by ID, discarding any associated payload.
Declaration
public bool Remove(int itemID)
Parameters
| Type | Name | Description |
|---|---|---|
| int | itemID | ID of the item to remove. |
Returns
| Type | Description |
|---|---|
| bool |
|
Remove(int, out T)
Removes an item by ID and returns its associated payload via an out parameter.
Declaration
public bool Remove(int itemID, out T payload)
Parameters
| Type | Name | Description |
|---|---|---|
| int | itemID | ID of the item to remove. |
| T | payload | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
The payload is retrieved (if it exists) before the structural removal. If the item
had no payload stored (for example if it was inserted without a payload), payload
is set to default(T).
TryGetPayload(int, out T)
Retrieves the typed payload associated with the given item ID.
Declaration
public bool TryGetPayload(int itemID, out T payload)
Parameters
| Type | Name | Description |
|---|---|---|
| int | itemID | ID of the item whose payload should be retrieved. |
| T | payload | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
The payload dictionary is queried independently of the spatial tree. An item that was
inserted via Add(int, ScyllaAABB3) (the non-generic overload) will not
have an entry in the payload dictionary; this method will return false for such items.
Update(int, ScyllaAABB3)
Updates the spatial bounds of an existing item without changing its payload.
Declaration
public bool Update(int itemID, ScyllaAABB3 newBounds)
Parameters
| Type | Name | Description |
|---|---|---|
| int | itemID | ID of the item to update. |
| ScyllaAABB3 | newBounds | New spatial bounds. Must be within the root loose bounds. |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
Delegates directly to Update(int, ScyllaAABB3). The payload stored in
_payloadByID is not touched. To update both bounds and payload, remove the item
and re-add it with the new values.