Search Unity

Feedback EntityManager methods in ComponentSystem?

Discussion in 'Entity Component System' started by ComputerKim, Feb 8, 2020.

  1. ComputerKim

    ComputerKim

    Joined:
    Jan 6, 2019
    Posts:
    15
    I have been experimenting with DOTS and I was wondering if it would be a good idea for Unity to implement the EntityManager methods in ComponentSystem?

    What I mean is:
    Code (CSharp):
    1. public class MySystem : ComponentSystem
    2. {
    3.     protected override void OnUpdate()
    4.     {
    5.         Entities.WithNone<Translation>().ForEach((Entity entity) =>
    6.         {
    7.             var m = World.EntityManager;    // Why do I have to do this?
    8.             m.AddComponent<Translation>(entity);
    9.  
    10.             AddComponent<Translation>(entity);  // When this could be enough?
    11.         });
    12.     }
    13. }
    Right now I have implemented my own extension method, but with that I have to use the 'this' keyword, so it would be nice if this could be implemented.
    Code (CSharp):
    1. public static partial class ExtensionMethods
    2. {
    3.     public static void AddComponent<T>(this ComponentSystem c, Entity entity)
    4.     {
    5.         c.World.EntityManager.AddComponent<T>(entity);
    6.     }
    7. }
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,270
    EntityManager is a porperty of ComponentSystem, so you don't need to do World.EntityManager.