Search Unity

how can i modify ECS Packages ?

Discussion in 'Entity Component System' started by Opeth001, Dec 18, 2019.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    Hello,
    im looking for a way to change few systems in the Entities package to fit my game needs but each time i modify a line of code the editor throws errors like:
    The type or namespace name 'CWBR' could not be found (are you missing a using directive or an assembly reference?)

    Thank you.
     
  2. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Usually when i feel the need to change something on such a system i copy that system into my project/package, change or remove its namespace and disable the original system on the new system's OnCreate() method.
     
    Opeth001 likes this.
  3. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    what do you mean by this ?

    how do you manage the dependencies of this system if you change it's namespace ?
     
  4. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    If you don't change the name you'll end up with duplicated system names.
    I only do this if the system doesn't access internals.
    What is the specific system that you want to change?
     
  5. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    like CopyTransformToGameObjectSystem and few others.
    why you put it in the Package folder if you will change it's name ? it doesn't work if you just put it in the Assets folder ?
     
  6. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    I think writegroup is for that purpose, though never use it before.
     
    Opeth001 likes this.
  7. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    For CopyTransformToGameObjectSystem it would be like this:
    Code (CSharp):
    1. using Unity.Burst;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4. using Unity.Jobs;
    5. using Unity.Mathematics;
    6. using Unity.Transforms;
    7. using UnityEngine.Jobs;
    8.  
    9. namespace YourNamespace {
    10.   [UnityEngine.ExecuteAlways]
    11.   [UpdateInGroup(typeof(TransformSystemGroup))]
    12.   [UpdateAfter(typeof(EndFrameLocalToParentSystem))]
    13.   public class CopyTransformToGameObjectSystem : JobComponentSystem {
    14.     [BurstCompile]
    15.     struct CopyTransforms : IJobParallelForTransform {
    16.       [DeallocateOnJobCompletion]
    17.       [ReadOnly] public NativeArray<LocalToWorld> LocalToWorlds;
    18.  
    19.       public void Execute(int index, TransformAccess transform) {
    20.         var value = LocalToWorlds[index];
    21.         transform.position = value.Position;
    22.         transform.rotation = new quaternion(value.Value);
    23.       }
    24.     }
    25.  
    26.     EntityQuery m_TransformGroup;
    27.  
    28.     protected override void OnCreate() {
    29.       m_TransformGroup = GetEntityQuery(ComponentType.ReadOnly(typeof(CopyTransformToGameObject)), ComponentType.ReadOnly<LocalToWorld>(), typeof(UnityEngine.Transform));
    30.      
    31.       // Disable original system
    32.       World.GetOrCreateSystem<Unity.Transforms.CopyTransformToGameObjectSystem>().Enabled = false;
    33.     }
    34.  
    35.     protected override JobHandle OnUpdate(JobHandle inputDeps) {
    36.       var transforms = m_TransformGroup.GetTransformAccessArray();
    37.       var copyTransformsJob = new CopyTransforms {
    38.         LocalToWorlds = m_TransformGroup.ToComponentDataArray<LocalToWorld>(Allocator.TempJob, out inputDeps),
    39.       };
    40.  
    41.       return copyTransformsJob.Schedule(transforms, inputDeps);
    42.     }
    43.   }
    44. }
    Note the line disabling the original system.
     
  8. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    You can only use it if the components to query have any write group and that is not often the case.
     
    eterlan likes this.
  9. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117

    Awesome thanks!
    does the line disabling the original system makes any difference if i just write this.Enabled = false; ? (just want to learn if im missing something ^_^)
     
    Last edited: Dec 19, 2019
  10. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    You have to disable the concrete system (Unity.Transforms.CopyTransformToGameObjectSystem in this example), if you use this you will be disabling your new system instead, and that is not what you want here.
     
    Opeth001 likes this.
  11. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    oh i got it :)
    i didn't see the "YourNamespace" i thought it was the original System XD.

    Thank a lot!
     
    GilCat likes this.