Skip to content

Game.Prefabs.LoadedIndex

Assembly:
Assembly-CSharp (inferred — game mod assembly where Game.Prefabs resides)

Namespace:
Game.Prefabs

Type:
struct

Base:
System.ValueType, Unity.Entities.IBufferElementData

Summary:
A small ECS buffer element that stores a single integer index. This struct is intended to be used as an IBufferElementData in Unity's DOTS/ECS DynamicBuffer for tracking a "loaded" prefab or resource index per-entity. The type is marked with InternalBufferCapacity(1) so a single element can usually be stored inline on the entity (avoiding a heap allocation) until the buffer grows beyond that capacity.


Fields

  • public int m_Index
    Holds the numeric index (for example a prefab index or loaded-resource identifier). Use this to record which prefab/resource is associated with the buffer entry. Because LoadedIndex is a blittable value type containing a single int, it is efficient for use in DynamicBuffer and safe for Burst/Jobs.

Properties

  • None.
    This struct exposes only a public field and implements IBufferElementData; there are no properties.

Constructors

  • Implicit parameterless constructor (default)
    As a C# struct, LoadedIndex has an implicit parameterless constructor that initializes m_Index to 0. You can create instances with aggregate initialization: new LoadedIndex { m_Index = someValue }.

Methods

  • None.
    This type is a plain data container (POD) with no methods.

Usage Example

// Add a LoadedIndex buffer to an entity and store an index:
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var e = em.CreateEntity();

// Ensure the buffer exists on the entity
var buffer = em.AddBuffer<Game.Prefabs.LoadedIndex>(e);

// Add an index (e.g. prefab id or loaded resource id)
buffer.Add(new Game.Prefabs.LoadedIndex { m_Index = prefabIndex });

// Read back the first stored index
if (buffer.Length > 0)
{
    int storedIndex = buffer[0].m_Index;
}

Additional notes: - The [InternalBufferCapacity(1)] attribute sets the internal inline capacity to 1 element — useful to avoid allocation when you typically store a single index. - Consider using a sentinel value (e.g. -1) to represent "no index assigned" if 0 is a valid index in your system. - This type is intended for use with Unity.Entities.DynamicBuffer in systems and jobs.