InvalidOperationException while dealing with ComponentLookup

Hi,

I’m trying to write a piece of code based on the pattern I’ve seen elsewhere, but I’m getting a runtime error. My code looks similar to what I see in SnakeSystems.cs from EntitiesSamples.

I’ve a BeingSystem that works on Being IComponentData. In its OnUpdate I want to schedule a IJobEntity. The Execute method of that IJobEntity needs access to ComponentLookup, because I cannot do SystemAPI.GetComponent in the Execute method. My code looks like this

    [BurstCompile]
    [RequireMatchingQueriesForUpdate]
    [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    public partial struct BeingSystem : ISystem
    {
        ComponentLookup<Being> m_beingLookup;

        [BurstCompile]
        public void OnCreate(ref SystemState state)
        {
            state.RequireForUpdate<Being>();
            m_beingLookup = state.GetComponentLookup<Being>(true);
        }

        [BurstCompile]
        public void OnUpdate(ref SystemState state)
        {
            m_beingLookup.Update(ref state);

            new BeingIdleJob
            {
                BeingLookup = m_beingLookup,
            }.ScheduleParallel();
        }
    }

    [BurstCompile]
    partial struct BeingIdleJob : IJobEntity
    {
        [ReadOnly]
        public AgentSpatialPartitioningSystem.Singleton Spatial;
        [ReadOnly]
        public ComponentLookup<Being> BeingLookup;

        public void Execute(Entity entity, ref Being being)
        {
        }
    }
}

When I run this code, I get

InvalidOperationException: The writeable ComponentTypeHandle<com.bluemathsoftware.dots.Being> BeingIdleJob.JobData.__TypeHandle.__com_bluemathsoftware_dots_Being_RW_ComponentTypeHandle is the same ComponentLookup<com.bluemathsoftware.dots.Being> as BeingIdleJob.JobData.BeingLookup, two containers may not be the same (aliasing).

What am I doing wrong?

You can’t have a lookup for the same type of component you are accessing as one of the Execute parameters.

That must be it. Dropping ref Being being from the signature or changing ref to in fixes the error.
Thanks!

this worked like a charm. thanks!