Using ECS in static function inside job

Hi,
using static functions inside of jobs really helps to keep code clean. But somehow I’m restricted to just general solutions. Is there a method to use functions like “HasComponent<>()” inside a static function, e.g.:

Entities
    .ForEach(
    (Entity entity, int entityInQueryIndex) => {
        bool test = CheckIfComponentExists(entity);
        if(test){...}
    }).ScheduleParallel();


public static bool CheckIfComponentExists(Entity entity) {

    if (HasComponent<MYCOMPONENT>(entity)) {
        return true;
    }
    return false;
}

If I try to structure my code like this an error with missing object reference appears. Can somebody help me?

1 Like

You’ll need to pass through a ComponentDataFromEntity which has a HasComponent() function, into the static function.

1 Like