Best Practice For Storing an array of data in entity component #82
-
I have the use case, where an entity component must hold a navigation path. Currently, I use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Using NativeDynamicArray for this kind of thing is fine. You don't need necessarily to use entities for this though, you can have your own datastructure, in your own class, that you inject in engines. This practice is mixing OOP and ECS and I discussed It in my article about OOP abstraction in an ECS centric application. |
Beta Was this translation helpful? Give feedback.
-
I implemented my own buffer that resembles the unity buffer logic. That is burstable and also in continuous memory. It works by having an array that holds fixed capacity buckets and then is unsafely referenced using pointers and the unity map.CreateBufferCollection<PathNode>(group,capicity,bufferCapcity); and retrieving it is as simple as: map.TryGetBufferCollection<Node>(group, out var bufferCollection);
bufferCollection.TryGetBuffer(entityId, out var buffer); They are also managed by a reactive engine that removes buffers when an entry is removed. There are also other possibilities:
|
Beta Was this translation helpful? Give feedback.
Using NativeDynamicArray for this kind of thing is fine. You don't need necessarily to use entities for this though, you can have your own datastructure, in your own class, that you inject in engines. This practice is mixing OOP and ECS and I discussed It in my article about OOP abstraction in an ECS centric application.
You can also use a managed component, implementors can be any kind of object.
Since in future I want to make implementors less and less useful, I will introduce the concept of IManagedEntityComponent, so you can use normal c# arrays. Of course, you cannot burstify them, so if you need burst, either your own data structure or NativeDynamicArray is ok.