Created
April 22, 2020 20:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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