#using a ReadOnly attribute in a ComponentLookup in Entities.Foreach

1 messages · Page 1 of 1 (latest)

minor cedar
#

Is there an equivalent of the [ReadOnly] attribute inside an Entities.Foreach? In this sample code:

ComponentLookup<ExampleComponent> exampleComponentLookup = SystemAPI.GetComponentLookup<ExampleComponent>(true);
Entities.ForEach((Entity entity, ref InputRaycastData inputRaycastData) =>
{
    if (!exampleComponentLookup.TryGetComponent(entity, out ExampleComponent exampleComponent)) return;
//Rest of the code
}).ScheduleParallel();

This code will throw an error because you are supposed to use a readonly componentlookup in a parallel job. In an IJobEntity or ParallelFor jobs, we could use the [ReadOnly] tag, but it's not possible here in Entities.Foreach.

loud fossil
#

it's WithReadOnly(exampleComponentLookup)

#

but you shouldn't use Entities.ForEach

#

it's being removed in 2.0

minor cedar
#

I see, thanks @loud fossil

#

I just checked the docs, and I will just skip Entities.ForEach completely.