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?