docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Reuse a dynamic buffer for multiple entities

    If all entities of an IJobEntity need the same buffer, you can get that buffer as a local variable on the main thread before scheduling the job.

    The following code example shows how to use the same dynamic buffer for multiple entities. It assumes a dynamic buffer called MyElement exists and another component exists called OtherComponent.

    public void DynamicBufferExample(Entity e)
    {
        var myBuff = SystemAPI.GetBuffer<MyElement>(e);
        new MyJobEntity{MyBuffer  = myBuf}.Schedule();
    }
    
    Note

    If you use ScheduleParallel, you can't write to the dynamic buffer in parallel. Instead, you can use an EntityCommandBuffer.ParallelWriter to record changes in parallel. However, any structural changes invalidate the buffer.

    Additional resources

    • Access dynamic buffers from jobs
    In This Article
    Back to top
    Copyright © 2024 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)