LoginSignup
0
0

エラー対処 You must call JobHandle.Complete()

Last updated at Posted at 2024-04-14

以下エラーが出た時の解決方法について

InvalidOperationException: The previously scheduled job TriggerVolumePortalSystem:TriggerVolumePortalJob writes to the ComponentLookup TriggerVolumePortalJob.JobData.LocalTransformLookup. You must call JobHandle.Complete() on the job TriggerVolumePortalSystem:TriggerVolumePortalJob, before you can read from the ComponentLookup safely.

エラーの説明の通り、JobHandle.Complete()する必要があるようですが、
解決に手間取ったため、メモを残します。

私の場合、以下2行実施時にエラーが発生しました。

var transformLookup = SystemAPI.GetComponentLookup<LocalTransform>();
var startPosition = transformLookup[_playerEntity].Position;

どうやら、.PositionでEntityの情報にアクセスするのと、既存のJOBの動作が干渉してしまっているようです。

解決としては、

state.Dependency = new TriggerVolumePortalJob()
{
    LocalTransformLookup = SystemAPI.GetComponentLookup<LocalTransform>(),
}.Schedule(state.Dependency);

[BurstCompile]
partial struct TriggerVolumePortalJob : IJobEntity
{
    public ComponentLookup<LocalTransform> LocalTransformLookup;        
    LocalTransformLookup[portalEntity].Position);

のように記述する。
state.Dependency が肝のようです。海外のUNITYマニュアルとか、Discordの技術トピックとか色々調査しましたが、コードの意味は完全にはわかりませんでした。とりあえずはおまじないだと思って注意していくしかなさそうです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0