SharedComponents are a pain because they can contain objects, but it seems that lots of programmers would be very happy with a struct only SharedComponent :
Same rules as IComponentData: struct, only blittable members, no arrays.
Same impact on chunks as current ISharedComponentData
example :
Struct PlanetData {
public readonly ushort Id;
public readonly ushort Radius;
public readonly int3 Position;
public PlanetData(ushort id, ushort radius, int3 center)
{
Id = id;
Radius = radius;
Position = center;
}
}
So a little more explanation to my use cases:
I make quadtree based planets, a planet is made of a set of nodes.
I need to process planets one by one, I m definitely not interested in other planets nodes so a sharedcomponent PlanetData would make sense for the ecs chunks.
But it’s too much of a pain with the current non-struct shared data, I often need the radius and position in my jobs so for now I just made that a IComponentData and so I’m wasting memory.
My nodes have a level. 0 for the biggest (less detailed) ones, 12 for the more detailed.
It would make sense to have a Level SharedComponent ( struct with just a byte !) so all the nodes of the same level are in the same chunks, and so that I could priorise work on the highest level of detail.
But for now, I’m just using a level11 IComponentData and level12 empty IComponentData.
For immutable data it seems like you could use BlobAssetReference. But for dynamic shared data things are more difficult. Can you use Entity references and store data on a separate entity? Getting it by ComponentDataFromEntity<>? But some easy API for shared data would be great.
There is some value in being able to share/define data at the level of an Archetype that doesn’t seem as well suited at the Entity/Chunk level. Sorting chunks of multiple archetypes based on some archetype value is an example. For now I keep track of this Archetype/Value relationship in a hash map but only because there isn’t a well suited method of doing this in the current ECS API.