Game.AmbientAudioEffect
Assembly: Assembly-CSharp
{{ Defined in the game's/mod assembly (commonly Assembly-CSharp) as part of the Game prefabs code. }}
Namespace: Game.Prefabs
{{ Grouping for prefab-related ECS types; used to attach ambient audio effect references to prefab or runtime entities. }}
Type: struct
Base: Unity.Entities.IBufferElementData
{{ This type implements IBufferElementData, so it is intended to be stored in a DynamicBuffer on an entity. It's a simple, blittable buffer element containing an Entity reference. }}
Summary:
{{ Represents a single ambient-audio effect reference. Each element holds an Entity that points to an audio effect prefab or an instantiated audio effect entity. Attach a DynamicBuffer
Fields
public Unity.Entities.Entity m_Effect
{{ The Entity reference to the ambient audio effect (usually a prefab converted to an entity or an instantiated effect entity). Each buffer element represents one effect. When iterating the buffer you can instantiate, enable, or otherwise manage the referenced effect entity. }}
Properties
None
{{ This struct does not expose properties — it is a plain data-only buffer element. Use the public field to read/write the referenced Entity. }}
Constructors
public AmbientAudioEffect()
{{ Default parameterless constructor provided by C# for structs. You can initialize this element with an object initializer:new AmbientAudioEffect { m_Effect = someEntity }
. If you prefer, define convenience constructors in your own code, but none are present in the original source. }}
Methods
None
{{ There are no methods on this struct. All manipulation is done through the DynamicBufferAPI, EntityManager, or an EntityCommandBuffer in systems/jobs. }}
Usage Example
// Add a buffer and push an effect reference (synchronous, main thread)
var buffer = entityManager.AddBuffer<AmbientAudioEffect>(targetEntity);
buffer.Add(new AmbientAudioEffect { m_Effect = ambientEffectPrefabEntity });
// Using an EntityCommandBuffer from a system (job-safe structural change)
ecb.AddBuffer<AmbientAudioEffect>(targetEntity);
ecb.AppendToBuffer(targetEntity, new AmbientAudioEffect { m_Effect = ambientEffectPrefabEntity });
// Iterating a buffer and instantiating each referenced effect
Entities.ForEach((Entity owner, in DynamicBuffer<AmbientAudioEffect> effects) =>
{
foreach (var e in effects)
{
var instance = entityManager.Instantiate(e.m_Effect);
// Parent, position, or configure the instantiated audio entity as needed.
}
}).WithoutBurst().Run();
{{ Notes:
- Use EntityCommandBuffer when modifying buffers from jobs or from parallel systems to avoid structural-change exceptions.
- The stored Entity is a raw entity reference; ensure the referenced entity/prefab is valid (converted and present).
- Because this is an IBufferElementData, it is blittable and job-friendly; however, any instantiation / structural changes should use the appropriate APIs for thread safety.
- To author these in conversion, add a DynamicBuffer