Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Help needed, error CS1061: 'Collider' does not contain a definition for 'ColliderPtr'

Discussion in 'Physics for ECS' started by DizzyTornado, May 26, 2022.

  1. DizzyTornado

    DizzyTornado

    Joined:
    Nov 17, 2013
    Posts:
    134
    Hi guys!
    I am wanting to change the size of a sphere collider on a entity. I am essentially using the code from here copy pasted and I am getting the above error. Anybody know how to fix this? Thanks.
    Code (CSharp):
    1.  
    2. unsafe
    3. {
    4.                 // grab the sphere pointer
    5.                 Unity.Physics.SphereCollider* scPtr = (Unity.Physics.SphereCollider*)GetComponent<Unity.Physics.Collider>().ColliderPtr;
    6.                  // update the collider geometry
    7.                 var sphereGeometry = scPtr->Geometry;
    8.                 sphereGeometry.Radius = nodeScale;
    9.                 scPtr->Geometry = sphereGeometry;
    10.  }
    11.  
     
  2. DizzyTornado

    DizzyTornado

    Joined:
    Nov 17, 2013
    Posts:
    134
    Fixed it.
    Updated code:
    Code (CSharp):
    1. unsafe
    2. {
    3.                 // grab the sphere pointer
    4.                 SphereCollider* scPtr = (SphereCollider*)entityManager.GetComponentData<PhysicsCollider>(entity).ColliderPtr;            
    5.                  // update the collider geometry
    6.                 var sphereGeometry = scPtr->Geometry;
    7.                 sphereGeometry.Radius = nodeScale;
    8.                 scPtr->Geometry = sphereGeometry;
    9. }
     
  3. DizzyTornado

    DizzyTornado

    Joined:
    Nov 17, 2013
    Posts:
    134
    Nevermind, this fixed compiler errors, however it does not change the scale of the collider. Does anyone know what it is missing?
     
  4. DizzyTornado

    DizzyTornado

    Joined:
    Nov 17, 2013
    Posts:
    134
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,505
    Blob assets are designed to be immutable - you are not meant to change their values.
    If you want to change your collider create a new one and assign it to the entity.
     
  6. DizzyTornado

    DizzyTornado

    Joined:
    Nov 17, 2013
    Posts:
    134
    Hmmm, I see, though in the case I do need to change the value. I've seen a bunch of examples online (including that one that is from Unity's own ECS examples) that change it this way. (The code above is from a official Unity example repository) I understand it might not be good practice but in this specific case it is necessary.
     
  7. DizzyTornado

    DizzyTornado

    Joined:
    Nov 17, 2013
    Posts:
    134
    FIXED: Turns out my collider data struct was set to a box collider not a sphere collider, switching it fixed the problem. Expected behavior now occurs.