Game.Tools.ExtraFeedback
Assembly:
Assembly-CSharp (typical for game/mod scripts) {{ If you know a different assembly for your mod, replace this accordingly. }}
Namespace: Game.Tools
Type:
struct
Base:
Unity.Entities.IBufferElementData
[InternalBufferCapacity(32)] applied to the struct — indicates a default internal buffer capacity of 32 elements before heap allocation.
Summary:
ExtraFeedback is a lightweight IBufferElementData element that holds a reference to an Entity prefab. It is intended to be used as a dynamic buffer on an entity so that multiple "extra feedback" prefabs can be associated with a single entity (for example, visual or audio feedback prefabs to spawn). Because it implements IBufferElementData and contains only an Entity, it is blittable and safe to use in jobs and DOTS systems.
Fields
public Unity.Entities.Entity m_Prefab
Reference to an Entity prefab to be used as extra feedback (e.g., an effect or visual/audio prefab to instantiate). Each buffer entry stores one prefab reference. The struct is decorated with [InternalBufferCapacity(32)], which gives each entity a stack-allocated buffer capacity of 32 entries before a heap allocation occurs.
Properties
- (none)
This type does not expose properties; it is a plain buffer element struct.
Constructors
- (implicit default)
The struct uses the implicit default constructor. You typically set the m_Prefab field when adding the element to a buffer.
Methods
- (none)
No methods are defined on this buffer element type.
Usage Example
using Unity.Entities;
using Game.Tools;
// Add a buffer to an entity and add a prefab reference to it:
public void AddExtraFeedback(EntityManager entityManager, Entity targetEntity, Entity feedbackPrefab)
{
// Ensure the entity has the buffer
var buffer = entityManager.GetBuffer<ExtraFeedback>(targetEntity);
// Add a new buffer element with the prefab reference
buffer.Add(new ExtraFeedback { m_Prefab = feedbackPrefab });
}
// In a System, iterating over entities with the buffer:
public partial class SpawnExtraFeedbackSystem : SystemBase
{
protected override void OnUpdate()
{
var ecb = new EntityCommandBuffer(Unity.Collections.Allocator.Temp);
Entities
.WithName("SpawnExtraFeedback")
.ForEach((Entity entity, in DynamicBuffer<ExtraFeedback> feedbackBuffer) =>
{
foreach (var entry in feedbackBuffer)
{
var prefab = entry.m_Prefab;
if (prefab != Entity.Null)
{
// Example: instantiate the prefab (this must be done appropriately for your codebase)
var instance = ecb.Instantiate(prefab);
// Optionally set transform or other components on instance
}
}
}).Run();
ecb.Playback(EntityManager);
ecb.Dispose();
}
}
Notes and tips: - Because ExtraFeedback contains only an Entity, it is safe to use in jobs and DOTS systems and supports burst compilation where applicable. - InternalBufferCapacity(32) is a performance hint — if you expect many more than 32 entries frequently, consider capacity and memory implications. - Ensure prefab Entities are valid (not Entity.Null) and created/loaded in the same EntityManager context you use to instantiate them.