Search Unity

Question (Solved) Help with ecs Physics Material (MaterialFlags is inaccessible)

Discussion in 'Physics for ECS' started by MatteoMazzeriBlasph, Mar 22, 2021.

  1. MatteoMazzeriBlasph

    MatteoMazzeriBlasph

    Joined:
    Jan 4, 2019
    Posts:
    12
    Hi,

    I would like to set a trigger collider to my entity via script. I create a capsule collider with it's geometry and filter but now I want to assign also the material

    BlobAssetReference<Unity.Physics.Collider> collider = Unity.Physics.CapsuleCollider.Create( capsuleGeometry, filter, material);

    The material I want to create and assign must have the flag trigger but when I try to do that I get the error Material.MaterialFlags is inaccessible. So how can i handle it?

    Thank you
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Just set Material.CollisionResponse = CollisionResponsePolicy.RaiseTriggerEvents, it will handle those flags internally.
     
  3. MatteoMazzeriBlasph

    MatteoMazzeriBlasph

    Joined:
    Jan 4, 2019
    Posts:
    12
    Hi, thank you for your help. This solved the issue.
    Do you know if it is possible to add two collider to the same entity? I tried with add componentData() but it seem to add only the second one
     
  4. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    You can only add one PhysicsCollider component to an Entity, however you can create a CompoundCollider made up from a number of other convex Colliders.
     
  5. MatteoMazzeriBlasph

    MatteoMazzeriBlasph

    Joined:
    Jan 4, 2019
    Posts:
    12
    Hi, Thank you for your answer. This is just for 2D Entities or also for Entities in general? I can't find documentation on it
     
  6. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    It's for all Entities. Entity can have a maximum of 1 PhysicsCollider component.
     
  7. MatteoMazzeriBlasph

    MatteoMazzeriBlasph

    Joined:
    Jan 4, 2019
    Posts:
    12
    Thank you mates, I solved all my issues. I ended up with instantiating an entity with a trigger collider as child of another entity setting up the main entity as parent and synchronizing their matrix
     
    petarmHavok likes this.