If SomeClassComponentData has an array in it, and is followed by any other AddComponentData of a struct, the following error will be thrown:
ArgumentException: Requested value outside bounds of UnsafeAppendOnlyBuffer. Remaining bytes: {Buffer->Size - m_Offset} Requested: {structSize}
Some dummy code to illustrate.
public class TestAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
dstManager.AddComponentData(entity, new SomeClassComponentDataWithArray());
dstManager.AddComponentData(entity, new SomeStructComponentData());
}
}
The above does not work, while the below does:
public class TestAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
dstManager.AddComponentData(entity, new SomeStructComponentData());
dstManager.AddComponentData(entity, new SomeClassComponentDataWithArray());
}
}
I am not sure if this is intended, but I don’t know why the order matters and I believe the error message should be more clear.
in the new 0.2 Entities version it’s possible to use Managed types inside ComponentData types but it comes with a cost.
Added support for managed IComponentData types such as class MyComponent : IComponentData {} which allows managed types such as GameObjects or List<>s to be stored in components.
Users should use managed components sparingly in production code when possible as these components cannot be used by the Job System or archetype chunk storage and thus will be significantly slower to work with.
Refer to the documentation for component data for more details on managed component use, implications and prevention.
@Opeth001 : I know about that, the point of my post is to say that storing List (or Array) has a major limitation: It has to be part of the last component added to an Entity, otherwise it throws errors.
Should I? I did for ISharedComponentData as suggested by the console, but none of these messages appeared for the managed component date
From the release notes: Managed IComponentData no longer require implementing the IEquatable<> interface and overriding GetHashCode(). If either function is provided it will be preferred, otherwise the component will be inspected generically for equality.
I’m not 100% sure but this is what is written in their documentation of the 0.2 version.
Managed IComponentData must implement the IEquatable interface and override for Object.GetHashCode(). As well, for serialization purposes, managed components must be default constructible. link
class IComponentData does not require GetHashcode or IEquatable.
You can have an array in class IComponentData and it will get serialized.
Unfortunately we yesterday found a bug in the serializer (This will be fixed in next entities release)
For now you should be able to add another field after the array and then the bug should disappear. Sorry about that…