Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to add/remove a deserialized BlobAssetReference<Collider> to/from CollisionWorld?

Discussion in 'Entity Component System' started by MNNoxMortem, Oct 22, 2019.

  1. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    This is a follow-up question to https://forum.unity.com/threads/mos...ycast-targets-e-g-colliders-with-dots.759998/ but was split on purpose for google-friendliness.

    More general: How do I add a deserialized BlobAssetReference<Collider> to a PhysicsWorld, and therefore to a CollisionWorld?

    I would have expected that creating an Entity and adding a PhysicsCollider, Local2World, Translation and Rotation would be sufficient, but my PhysicsWorld still shows 0 bodies.

    I can see 1 MatchingChunk but still 0 Entities?
    upload_2019-10-22_21-34-49.png

    Code (CSharp):
    1. BlobAssetReference<Collider> deserializedCollider =
    2. UnityColliderSerialization.DeserializeCollider(serializedColliderPath);
    3.  
    4. var entityManager = World.Active.EntityManager;
    5. var entity        = entityManager.CreateEntity();
    6.  
    7. entityManager.AddComponentData(entity, new LocalToWorld {});
    8. entityManager.AddComponentData(entity, new Translation {Value = Vector3.zero});
    9. entityManager.AddComponentData(entity, new Rotation {Value    = Quaternion.identity});
    10.  
    11. // TEST: add collier
    12. var colliderComponent = new PhysicsCollider {Value = deserializedCollider};
    13. entityManager.AddComponentData(entity, colliderComponent);
     
  2. sschoener

    sschoener

    Joined:
    Aug 18, 2014
    Posts:
    73
    It seems to me that the physics systems have not been created at all: They are not in the list on the left. I'm not sure there is more I can say without further context or a project with the problem, as usually the physics systems should be automatically created.
     
  3. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @sschoener now that I have the example project from deserialization, I have just added the above few lines to it, so you know the project already :)

    I added the entity creation to: CollliderCreationExample.cs:63 to CollliderCreationExample.cs:82

    The behaviour is exactly the same as in my actual project:
    • Open it
    • Start it
    • Press "Create MeshCollider with Bursted IJob"
    • Open EntityDebugger

    Also I would say there is a bug in the Entity Debugger as clicking the line "Entity:0" causes errors to be logged infinitely.
     

    Attached Files:

  4. sschoener

    sschoener

    Joined:
    Aug 18, 2014
    Posts:
    73
    Actually, the project you posted here works just fine for me. The physics world is running, the physics systems are updating (with 2019.2.9f1).
     
    MNNoxMortem likes this.
  5. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @sschoener Interesting. Shouldn't I see the Entity with the Collider component in the Entity Debugger? Maybe just my expectations have been wrong.

    Update: Sometimes I can only scratch my head. The screenshot says "Enity 0" not "Entities: 0". There is one entity on index 0 and not 0 entities...

    Thank you anyway for looking into it :)
     
    Last edited: Oct 26, 2019