Jobs in ECS | Entities | 0.7.0-preview.19
docs.unity3d.com
    Show / Hide Table of Contents

    Jobs in ECS

    ECS uses the C# Job System extensively. Whenever possible, you should use the jobs in your system code. The SystemBase class provides Entities.ForEach and Job.WithCode to help implement your game logic as multithreaded code. In more complex situations, you can use IJobChunk.

    For example, the following system updates positions:

    using Unity.Burst;
    using Unity.Collections;
    using Unity.Entities;
    using Unity.Jobs;
    using Unity.Transforms;
    
    public class MovementSpeedSystem : SystemBase
    {
        // OnUpdate runs on the main thread.
        protected override void OnUpdate()
        {
            Entities
                .ForEach((ref Translation position, in MovementSpeed speed) =>
                    {
                        float3 displacement = speed.Value * dt;
                        position = new Translation(){
                                Value = position.Value + displacement
                            };
                    })
                .ScheduleParallel();
        }
    }
    

    For more information about systems, see ECS Systems.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023