Search Unity

Request: Optional Components in IJobProcessComponentData

Discussion in 'Entity Component System' started by Jay-Pavlina, Jan 26, 2019.

  1. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    IJobProcessComponentData should support optional components. In the generic arguments, they would have to be wrapped in a struct of some kind. In the execute method, you could just check if it exists before using it. It could be something like this:

    Code (CSharp):
    1. struct Job : IJobProcessComponentData<Optional<Position>> {
    2.     public void Execute(<Optional<Position>> c0) {
    3.         if (c0.exists)
    4.             c0.x += 10;
    5.     }
    6. }
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Just use ComponentDataFromEntity<Position>

    which has an Exists(entity) method
     
  3. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    That requires more code. Considering how difficult it is to reuse code on jobs due to them being structs, I think we should reduce boilerplate as much as possible.