this is example, it throw exception. please how to write and read same component in two entity?
what is the best implementable? what is best performance?
thank.
cannot change readonly ComponentLookup to readwrite add [NativeDisableParallelForRestriction], because parallel other system readwrite PosComp.
Exception:
The writeable ComponentTypeHandle<Game.Editor.PosComp> Job.JobData.__TypeHandle.__Game_Editor_PosComp_RW_ComponentTypeHandle is the same ComponentLookup<Game.Editor.PosComp> as Job.JobData.Lookup, two containers may not be the same (aliasing).
public struct PosComp : IComponentData, IEnableableComponent
{
public float X;
public float Y;
}
public struct BindComp : IComponentData, IEnableableComponent
{
public Entity Target;
}
public partial struct BindSystem : ISystem
{
public void OnUpdate(ref SystemState state) => state.Dependency = new Job()
{
Lookup = SystemAPI.GetComponentLookup<PosComp>(true),
}.ScheduleParallel(state.Dependency);
[WithAll(typeof(PosComp), typeof(BindComp))]
private partial struct Job : IJobEntity
{
[ReadOnly] public ComponentLookup<PosComp> Lookup;
private void Execute(ref PosComp pos, in BindComp bind)
{
var target = Lookup[bind.Target];
pos.X = target.X;
pos.Y = target.Y;
}
}
}