Skip to content

Game.Prefabs.AudioRandomizeData

Assembly:
Assembly-CSharp (typical Unity game assembly; the exact assembly may vary by build / mod setup)

Namespace:
Game.Prefabs

Type:
struct

Base:
Unity.Entities.IBufferElementData

Summary:
AudioRandomizeData is a small ECS buffer element used to hold references to one or more SFX (sound effect) entities for randomized audio playback. The struct is attributed with InternalBufferCapacity(2), which indicates the entity will store up to 2 elements inline (on the entity) for performance; additional elements will be allocated on the heap. This type is intended for use in DOTS/Entities systems where an entity needs a small, variable-length list of audio SFX entities to choose from.


Fields

  • public Unity.Entities.Entity m_SFXEntity
    Holds a reference to an Entity that represents a sound effect (SFX) prefab or audio entity. Each buffer element corresponds to one SFX candidate for random selection.

  • Attribute: [InternalBufferCapacity(2)]
    Specifies the internal (inline) capacity of the DynamicBuffer for this element type. A capacity of 2 keeps small lists allocation-free in most cases.

Properties

  • (none)
    This is a plain struct implementing IBufferElementData; it exposes a single public field and no properties.

Constructors

  • (none declared)
    As a value type (struct), it uses the default parameterless constructor. Create instances with object initializer syntax: new AudioRandomizeData { m_SFXEntity = someEntity }.

Methods

  • (none)
    No methods are defined on this buffer element. Behavior is provided by user code / systems that read or write the DynamicBuffer.

Usage Example

// Add a buffer to an entity and populate it (EntityManager approach)
var sfxContainer = entityManager.CreateEntity();
var buffer = entityManager.AddBuffer<Game.Prefabs.AudioRandomizeData>(sfxContainer);

// Add up to (and beyond) the inline capacity; first 2 will be stored inline
buffer.Add(new Game.Prefabs.AudioRandomizeData { m_SFXEntity = sfxEntityA });
buffer.Add(new Game.Prefabs.AudioRandomizeData { m_SFXEntity = sfxEntityB });

// Iterate in a system to play a random SFX from the buffer
Entities.ForEach((in DynamicBuffer<Game.Prefabs.AudioRandomizeData> audioList) =>
{
    if (audioList.Length == 0) return;
    int index = UnityEngine.Random.Range(0, audioList.Length);
    var chosen = audioList[index].m_SFXEntity;
    // Use chosen entity with your audio playback system or spawn logic
}).WithoutBurst().Run();

Additional notes for modders: - Use DynamicBuffer on entities that represent audio containers or components that need multiple candidate SFXs. - Keep lists small when possible to benefit from the inline capacity of 2; otherwise allocations will occur. - Ensure the referenced Entity SFX prefabs are valid (created/loaded) before attempting playback.