Using ECS to update a mesh.

Yes, I’ve talked about it a bit before here: Allow setting mesh arrays with NativeArrays.

keijiro had a great demo of it here which is what I based this all off: GitHub - keijiro/Firefly: Unity ECS example for special effects

Either you just modify a T directly in a job using pointers (faster method) or do a memcopy (slightly slower, but cleaner, safer and shouldn’t be your bottleneck anyway)

I even benchmarked it further down, but i’ll repost it here.

Default NativeArray.CopyTo (2.40ms)

Array.CopyTo - very similar to Marshal performance (0.15ms)

My custom UnsafeNativeArray - directly editing the array, no copying (0.07ms)

So relative performance between Array.Copy and directly editing array isn’t huge, however it does halve your memory requirement as you don’t require 2 copies of the array - not a big deal if you only need a single array but if you need a lot it’s signficant.

6 Likes