Skip to content

Instantly share code, notes, and snippets.

@Refsa
Created April 22, 2020 20:55
Show Gist options
  • Save Refsa/72362b44062dbaf11debbac792237ed1 to your computer and use it in GitHub Desktop.
Save Refsa/72362b44062dbaf11debbac792237ed1 to your computer and use it in GitHub Desktop.
Unity DOTS: How to use Deferred Array function on NativeList to consume the lists content before it's job has completed
protected override void OnUpdate()
NativeList<int> testList = new NativeList<int>(10, Allocator.TempJob);
Job.
WithCode(
() => {
for (int i = 0; i < 10; i++)
testList.Add(i);
}
)
.Schedule();
NativeArray<int> testListDeferred = testList.AsDeferredJobArray();
NativeArray<int> pow = new NativeArray<int>(10, Allocator.TempJob);
Job
.WithCode(
() => {
for (int i = 0; i < 10; i++)
{
pow[i] = testListDeferred[i] * testListDeferred[i];
}
}
)
.WithReadOnly(testListDeferred)
.Schedule();
this.Dependency = testList.Dispose(this.Dependency);
this.CompleteDependency();
for (int i = 0; i < 10; i++)
{
UnityEngine.Debug.Log($"{pow[i]}");
}
pow.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment