#Can Native Containers be used in IComponentData?
1 messages · Page 1 of 1 (latest)
they can totally be put on components and i use them frequently like this to pass data between systems
but I only do this from system create and destroy
you still need to manager their memory
I assume you do this by initializing the Native container size during baking, then make sure that when allocating the data on system create that you use the same size.
Is that right?
There's no baking here at all from me
Actually I think I just confused myself by not being specific.
Can you safely use NativeContainers in unmanaged components?
Or do you need to have managed components to use them safely?
you can use them on unmanaged components
How so?
When I bake components with NativeContainers it throws a blittable error because of the NAtiveContainer pointer.
Is it just only adding components to objects outside of the baking step?
again i never bake native containers
even if they aren't allocated
but if you want to bake a pointer you have to tell unity that this is ok
put
[ChunkSerializable]
on the component
/// States that a component type is serializable.
/// </summary>
/// <remarks>
/// By default, ECS does not support storing pointer types in chunks. Apply this attribute to a component declaration
/// to allow the use of pointers as fields in the component.
///
/// Note that ECS does not perform any pre- or post-serialization processing to maintain pointer validity. When
/// using this attribute, your code assumes responsibility for handling pointer serialization and deserialization.
/// </remarks>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class ChunkSerializableAttribute : Attribute```
NativeContainers are fully supported at runtime in components (managed and unmanaged).
But yes, containers are not serialized - so baking wouldn't work 😄
I would like official to make it work. I guess it's possible?
Well, not for 1.0 :3