All ECS tutorials are very clear and easy to understand when there is no need to transfer data from one entity to another. But what if you need to?
I have built a lot of things with jobs and NativeArrays, but now I want to rewrite them to ECS, because (I recon) it will be better off in the long run, and also have more performance benefits. Now, with non-ECS, NativeArray only approach, cross-referencing elements of 2 arrays is fairly easy, because we have indices and you can directly “point” into an array spot to read or write data, whichever is necessary. You can write parallel jobs that use 2 arrays (considering we don’t write to the same spot, that is).
A simple architecture to imagine is a graph, where you have nodes and links. There are nodes that can be linked to any other node. Nodes can process things on themselves, and links can process things on themselves (those systems are clear), but then at some point, they need to transfer data, a link needs to influence nodes, or a node needs to influence another node.
Another problem is when the entities are adjacent, lets say we have a grid of nodes, and I just simply want to transfer something to the adjacent node. Of course in NativeArray approach again this is simple because the next node is just myArray[x+1], but in ECS I’m just dumbfounded how to do something as simple as that.
I have tried a few things…
I thought IJobChunk might be a better solution, but it again appears to only work for iterating over an entity itself, not being able to change or get data from other entities’ components (or am I missing something?). I tried using a NativeMultiHashMap as a buffer for link changes (because of the nature of node being able to be connected to an arbitrary number of links), but adding elements to it appears to be quite slow even in parallel. In the grid example, I managed to get it working by making a system that writes entity data into a NativeArray, and then other jobs would use this NativeArray to read off. But that seems a bit odd to need to copy data like that.
So far ECS has been great, but I’m just really confused about this one, and I’m having a hard time finding any useful articles on the “general philosophy” or examples on it that make sense in my case.
Also, do you think that moving stuff like grid data to ECS is a good approach, or should it be left to just processing NativeArray in parallel jobs? As far as I understand with just processing NativeArray you don’t get the benefits of SOA SIMDification of data (and operations on entities themselves do appear much faster in profiler), am I correct?