Instantly share code, notes, and snippets.

Embed
What would you like to do?
エラーになるGetComponentDataFromEntityの使い方
using Unity.Entities;
using Unity.Jobs;
using Unity.Collections;
using Unity.Burst;
using Unity.Transforms;
using Unity.Mathematics;
using UnityEngine;
public class FollowTargetSystem : JobComponentSystem
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
inputDeps = new LookTargetJob {
deltaTime = Time.deltaTime,
positionFromEntity = GetComponentDataFromEntity<Position>(true)
}.Schedule(this, inputDeps);
return inputDeps;
}
[BurstCompile]
private struct LookTargetJob : IJobProcessComponentData<Target, Position>
{
[ReadOnly] public ComponentDataFromEntity<Position> positionFromEntity;
public float deltaTime;
public void Execute([ReadOnly] ref Target target, ref Position pos)
{
if (!positionFromEntity.Exists(target.Value))
return;
var targetPos = positionFromEntity[target.Value];
var diff = targetPos.Value - pos.Value;
diff = math.normalize(diff);
pos.Value += diff * deltaTime;
}
}
}
@tsubaki

This comment has been minimized.

Owner

tsubaki commented Dec 1, 2018

InvalidOperationException: The writable NativeArray LookTargetJob.Iterator is the same NativeArray as LookTargetJob.Data.positionFromEntity, two NativeArrays may not be the same (aliasing).Unity.Jobs.LowLevel.Unsafe.JobsUtility.ScheduleParallelFor (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters, System.Int32 arrayLength, System.Int32 innerloopBatchCount) <0x157d64470 + 0x0007a> in :0Unity.Entities.JobProcessComponentDataExtensions.Schedule (System.Void* fullData, System.Int32 length, System.Int32 innerloopBatchCount, System.Boolean isParallelFor, Unity.Entities.JobProcessComponentDataCache& cache, Unity.Jobs.JobHandle dependsOn, Unity.Jobs.LowLevel.Unsafe.ScheduleMode mode) (at Packages/com.unity.entities@0.0.12-preview.21/Unity.Entities/IJobProcessComponentData.cs:503)Unity.Entities.JobProcessComponentDataExtensions.ScheduleInternal_2[T] (T& jobData, Unity.Entities.ComponentSystemBase system, System.Int32 innerloopBatchCount, Unity.Jobs.JobHandle dependsOn, Unity.Jobs.LowLevel.Unsafe.ScheduleMode mode) (at Packages/com.unity.entities@0.0.12-preview.21/Unity.Entities/IJobProcessComponentData.cs:554)Unity.Entities.JobProcessComponentDataExtensions.Schedule[T] (T jobData, Unity.Entities.ComponentSystemBase system, Unity.Jobs.JobHandle dependsOn) (at Packages/com.unity.entities@0.0.12-preview.21/Unity.Entities/IJobProcessComponentData.cs:423)FollowTargetSystem.OnUpdate (Unity.Jobs.JobHandle inputDeps) (at Assets/System/FollowTargetSystem.cs:13)Unity.Entities.JobComponentSystem.InternalUpdate () (at Packages/com.unity.entities@0.0.12-preview.21/Unity.Entities/ComponentSystem.cs:508)Unity.Entities.ScriptBehaviourManager.Update () (at Packages/com.unity.entities@0.0.12-preview.21/Unity.Entities/ScriptBehaviourManager.cs:77)Unity.Entities.ScriptBehaviourUpdateOrder+DummyDelagateWrapper.TriggerUpdate () (at Packages/com.unity.entities@0.0.12-preview.21/Unity.Entities/ScriptBehaviourUpdateOrder.cs:703)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment