Skip to content

engine-v3.0.0-preview.19

Latest
Compare
Choose a tag to compare
@friflo friflo released this 10 Dec 10:19
· 5 commits to main since this release
  • Changed implementation of EntityStore.CloneEntity()

    Old: Used JSON serialization as fallback if source entity has one or more non-blittable component types.
    E.g. a struct component containing fields with reference types like a array, List<> or Dictionary<,>.

    New: Non-blittable components are now cloned using a static CopyValue() method with must part of component type.
    E.g.

    public struct MyComponent : IComponent
    {
        public int[]   array;
      
        static void CopyValue(in MyComponent source, ref MyComponent target, in CopyContext context) {
            target.array = source.array?.ToArray();
        }
    }

    In case CopyValue() is missing an exception is thrown including the required method signature in the exception message.
    Info: Removing JSON serialization from cloning has additional advantages.

    1. Much faster as JSON serialization/deserialization is expensive.
    2. No precision loss when using floating point types.