public static void UndoChange(ComponentChange change)
    {
        Entity entity        = Entities.Find(change.EntityId);
        Type   componentType = change.IsRemoved?change.Before.GetType():change.After.GetType();

        if (change.IsRemoved)
        {
            // Add new component.
            if (entity == null)             // Add new entity.
            {
                entity = Entities.AddEntityFromSync(change.EntityId, change.Before);
            }
            else             // Add new component.
            {
                entity.AddComponent(change.Before);
            }
        }
        else
        {
            if (change.Before == null)
            {
                // Remove component.
                entity.RemoveComponent(componentType);
            }
            else
            {
                // Undo changes in existing component.
                EntityComponent existingComponent = entity.GetComponent(componentType);
                existingComponent.AddChange(change.Before);
            }
        }
    }
    public static void ApplyChange(ComponentChange change)
    {
        Entity entity        = Entities.Find(change.EntityId);
        Type   componentType = change.IsRemoved?change.Before.GetType():change.After.GetType();

        if (change.IsRemoved)
        {
            if (entity == null)
            {
                Debug.Log("Received intent to remove component from non-existing entity");
                return;
            }
            else
            {
                // Remove component.
                entity.RemoveComponent(componentType);
            }
        }
        else
        {
            EntityComponent existingComponent = entity == null ? null : entity.GetComponent(componentType);
            if (existingComponent == null)
            {
                if (entity == null)                 // Add new entity.
                {
                    entity = Entities.AddEntityFromSync(change.EntityId, change.After);
                }
                else                 // Add new component.
                {
                    entity.AddComponent(change.After);
                }
            }
            else
            {
                // Apply changes to existing component.
                existingComponent.AddChange(change.After);
            }
        }
    }