Search Unity

Reusing PhysicsCollider from subscene entities results in BlobAssetReference Invalid

Discussion in 'Physics for ECS' started by No3371, Oct 15, 2020.

  1. No3371

    No3371

    Joined:
    Dec 1, 2016
    Posts:
    42
    For some reason, I can not just instantiate preset entities but have to add the desired component data to entities created at runtime. My current approach is use sceneSystem to load the subscene and tracks the scene entities, take them as prefabs, and just assign the PhysicsCollider.Value (BlobAssetReference) to new PhysicsCollider and add it to new entities, this results in

    NullReferenceException: Object reference not set to an instance of an object
    Unity.Physics.Broadphase+BodyPairWriter.Flush () (at Library/PackageCache/com.unity.physics@0.5.0-preview.1/Unity.Physics/Collision/World/Broadphase.cs:989)

    and

    InvalidOperationException: The BlobAssetReference is not valid. Likely it has already been unloaded or released.
    Unity.Entities.BlobAssetReferenceData.ValidateNonBurst () (at Library/PackageCache/com.unity.entities@0.14.0-preview.19/Unity.Entities/Blobs.cs:254)


    I guess there's something I missed about BlobAssetReference, would you mind telling me what it is? Thanks!
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Sounds like a timing/scheduling issue, some code trying to access the collider before you've created it. Make sure you allocate this colliders before the BuildPhysicsWorld updates.
     
  3. No3371

    No3371

    Joined:
    Dec 1, 2016
    Posts:
    42
    Well It turned out that the collider lives in a blob that I dispose after the entity conversion. It was the first time I deal with DOTS Physics Collider so I didn't aware that it's not included in the component but just referenced.
     
    petarmHavok likes this.