Search Unity

Feedback Feature request: BlobAssetReference without copy

Discussion in 'Entity Component System' started by Baggers_, Aug 11, 2020.

  1. Baggers_

    Baggers_

    Joined:
    Sep 10, 2017
    Posts:
    98
    TLDR: BlobAssetReference.Create always copies, performing unneccesary allocations

    Whilst I'm not using the ECS itself due to it not fitting my projects needs, for the most part I'm loving the things I now have access to in these new apis. Jobs, BlobAssets, BatchRendererGroup, etc have been awesome.

    The access to the internals has been excellent, it's a relief to just be able to use unmanaged memory and get what I need even if it's rough around the edges.

    One odd outlier though is BlobAssetReference. When creating one it always allocates new memory and takes a copy of the data passed. This is aggrevating as even if I did lay out the memory correctly I have no way to make a BlobAssetReference to it (without ugly hackery).

    Currently the api means I load data, have BlobAssetReference copy it, and then I have to free the original so I don't have two copies around. Also I've now got N resources to Dispose later for (seemingly) no benefit.

    I understand there are the BlobAssetHeaders, but it feels like we could have a good API which still takes those into account.

    Anyway, just a humble request. Thank you so much for these awesome tools.



    p.s. To those who would suggest making a custom system: Then I'd have to take on the work to replicate something already existing and which would be incompatible with APIs using BlobAssetReference.
     
    burningmime likes this.
  2. Baggers_

    Baggers_

    Joined:
    Sep 10, 2017
    Posts:
    98
    I guess the issue might be really that APIs requiring BlobAssetReference specifically rather than some typed readonly reference that a BlobAssetReference could provide (and/or be cast to).

    The one in my mind right now is that RigidBodys need a reference to a BlobAssetReference specifically. If it were a struct Foo which was a readonly wrapper around a pointer, the RigidBody could require that and BlobAssetReference could provide an 'AsFoo' method (and an implicit cast operator which used AsFoo). This would give the option for users to manage the colliders themselves whilst still being able to interop with Unity.Physics

    I hope that was clear, it's a bit late here
     
    JesOb and burningmime like this.