#Can Native Containers be used in IComponentData?

1 messages · Page 1 of 1 (latest)

ivory wing
#

The Unity Docs say Native Containers can be used in components, but everything else makes that seem like a lie. Baking doesn't allow unknown sized types, so these cant be put safely in IComponents as far as I can tell.

Am I missing something or are Native containers just not allowed in IComponentData types?

hazy quest
#

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

ivory wing
#

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?

hazy quest
#

There's no baking here at all from me

ivory wing
#

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?

hazy quest
#

you can use them on unmanaged components

ivory wing
hazy quest
#

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```
stray atlas
#

NativeContainers are fully supported at runtime in components (managed and unmanaged).
But yes, containers are not serialized - so baking wouldn't work 😄

dry hollow
stray atlas
#

Well, not for 1.0 :3