Physics Material 2D change during runtime not taking effect.

Hey,
I have this gameObject that changes it PhysicsMaterial2D, on it’s CircleCollider2D during runtime, but it is still acting as if it doesn’t have the Physics Material.
I change it like this:

var yellowPMat : PhysicsMaterial2D;
function Update () {
	if (color == 'yellow') {
		gameObject.GetComponent(CircleCollider2D).sharedMaterial = yellowPMat;
	}
	else {
		gameObject.GetComponent(CircleCollider2D).sharedMaterial = null;
	}
}

I can see in the editor that the material on the CircleCollider2D is changing, but it is not having any effect on the ball’s bounciness (the bounciness in the PMat is 0.9) so I don’t know what’s happening.
I feel like I am missing something, so someone help me please. :stuck_out_tongue:
Thanks. :smiley:

I fixed it myself, but I am still unaware why the issue was occuring in the first place. To fix it I quickly flicked the collider on and off again.

var yellowPMat : PhysicsMaterial2D;

if (color == 'yellow') {
		gameObject.collider2D.sharedMaterial = yellowPMat;
		gameObject.collider2D.enabled = false;
		gameObject.collider2D.enabled = true;
		
	}
	else {
		gameObject.collider2D.sharedMaterial = null;
		gameObject.collider2D.enabled = false;
		gameObject.collider2D.enabled = true;
	}

So yeah, flicking it off and on again fixed my problem. :stuck_out_tongue: