docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface IBufferElementData

    An interface for creating structs that can be stored in a DynamicBuffer<T>.

    Namespace: Unity.Entities
    Assembly: Unity.Entities.dll
    Syntax
    [RequireImplementors]
    public interface IBufferElementData
    Remarks

    This is a variant of IComponentData which allows more than one value of a given type to be associated with an entity, in an ordered list.

    See Dynamic Buffers for additional information.

    Examples
    [InternalBufferCapacity(8)]
    public struct FloatBufferElement : IBufferElementData
    {
        // Actual value each buffer element will store.
        public float Value;
    
        // The following implicit conversions are optional, but can be convenient.
        public static implicit operator float(FloatBufferElement e)
        {
            return e.Value;
        }
    
        public static implicit operator FloatBufferElement(float e)
        {
            return new FloatBufferElement { Value = e };
        }
    }
    
    public partial class DynamicBufferExample : SystemBase
    {
        partial struct DynamicBufferJob : IJobEntity
        {
            public float Sum;
            void Execute(DynamicBuffer<FloatBufferElement> buffer)
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    Sum += buffer[i].Value;
                }
            }
        }
    
        protected override void OnUpdate()
        {
            var job = new DynamicBufferJob() { Sum = 0 };
            job.Run();
    
            Debug.Log("Sum of all buffers: " + job.Sum);
        }
    }
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)