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.
unsafe
{
// grab the sphere pointer
Unity.Physics.SphereCollider* scPtr = (Unity.Physics.SphereCollider*)GetComponent<Unity.Physics.Collider>().ColliderPtr;
// update the collider geometry
var sphereGeometry = scPtr->Geometry;
sphereGeometry.Radius = nodeScale;
scPtr->Geometry = sphereGeometry;
}
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.
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.
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.