Jobs in ECS | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Jobs in ECS

    ECS uses the Job system to implement behavior -- the System part of ECS. An ECS System is concretely a Job created to transform the data stored in entity components

    For example, the following system updates positions:

    using Unity.Burst;
    using Unity.Collections;
    using Unity.Entities;
    using Unity.Jobs;
    using Unity.Transforms;
    using UnityEngine;
    
    public class MovementSpeedSystem : JobComponentSystem
    {
        [BurstCompile]
        struct MovementSpeedJob : IJobForEach<Position, MovementSpeed>
        {
            public float dT;
    
            public void Execute(ref Position Position, [ReadOnly] ref MovementSpeed movementSpeed)
            {
                float3 moveSpeed = movementSpeed.Value * dT;
                Position.Value = Position.Value + moveSpeed;
            }
        }
    
        // OnUpdate runs on the main thread.
        protected override JobHandle OnUpdate(JobHandle inputDependencies)
        {
            var job = new MovementSpeedJob()
            {
                dT = Time.deltaTime
            };
    
            return job.Schedule(this, inputDependencies);
        }
    }
    

    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