Skip to content

Game.Prefabs.AudioSourceData

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: struct

Base: IBufferElementData

Summary:
AudioSourceData is an ECS buffer element used to store a reference to an SFX (sound effect) Entity. The struct is annotated with [InternalBufferCapacity(1)], which reserves space for one element in the entity chunk to avoid separate heap allocation for small buffers. Intended to be used via DynamicBuffer on entities that need to keep a link to one or more audio-related entities (commonly a single SFX entity).


Fields

  • public Unity.Entities.Entity m_SFXEntity
    Holds the Entity reference for the associated sound effect. May be Entity.Null if no SFX entity is assigned. This field is public and value-type (blittable) so it is suitable for use in jobs and ECS systems.

  • Attribute: [InternalBufferCapacity(1)]
    Applied to the buffer element type to set the internal buffer capacity to 1 (one element stored in-chunk). This improves performance for the common case when only a single AudioSourceData element is present.

Properties

  • This type has no properties.

Constructors

  • public AudioSourceData() (implicit)
    Struct has the default parameterless constructor. Default-initialized instances will have m_SFXEntity == Entity.Null.

Methods

  • This type defines no methods. It is a plain data container used with DynamicBuffer.

Usage Example

// assuming inside a System or setup code with access to an EntityManager
Entity sfxEntity = /* create or obtain SFX entity */;
Entity audioHolder = entityManager.CreateEntity();

// Add a dynamic buffer of AudioSourceData to audioHolder (if not present)
DynamicBuffer<Game.Prefabs.AudioSourceData> buffer = entityManager.AddBuffer<Game.Prefabs.AudioSourceData>(audioHolder);

// Store the SFX entity reference
buffer.Add(new Game.Prefabs.AudioSourceData { m_SFXEntity = sfxEntity });

// Later in a system you can read the buffer:
var audioBuffer = EntityManager.GetBuffer<Game.Prefabs.AudioSourceData>(audioHolder);
if (audioBuffer.Length > 0)
{
    var sfx = audioBuffer[0].m_SFXEntity;
    // use sfx (e.g., send play message or perform audio-related logic)
}

Additional notes: - Use DynamicBuffer in systems to read or write these entries. Because of the InternalBufferCapacity(1) attribute, small buffers (one element) will be stored in-chunk, avoiding extra allocations. - The contained Entity is safe to pass to jobs that accept Entity types, but ensure the referenced entity lives/exists when you access it (avoid using destroyed Entity references). - Keep buffer element types simple and blittable for best performance in Jobs/ECS contexts.