Search Issue Tracker
Fixed in 5.2.0
Votes
6
Found in
4.3.0f4
Issue ID
577228
Regression
No
Physics material has no effect when changed from code
Steps to reproduce :
- import the project attached
- open the scene and disable the "Assign Physic Material" script on the Floor objects
- play the scene and notice that the ball is bouncing
- while in play mode change the material to "Solid" for the box collider and notice that the ball stops
- press stop and enable the Assign Physic Material script
- press play and notice that the material change to "Solid" but the ball is bouncing
Comments (3)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [Android] The Player screen turns black when playing a video under certain conditions
- Search window icons at the bottom are cut off when Search window is resized vertically
- "Try something else?" text label is cut off when searching for a long text in the Search window
- Rendering Debugger window sections do not have a minimum width set when resizing with the slider in the middle of the window
- Last segment of a Sprite Shape Spline is affected by other segments' Sprite Variant change when no edge Sprite is selected
Maxxx50
Feb 07, 2017 16:33
Still present in 5.5.0f3 :(
You can follow the issue here : https://issuetracker.unity3d.com/issues/runtime-changes-to-friction-or-bounciness-in-physics-material-2d-have-no-effect-on-objects-which-use-that-physicsmaterial2d
Randy O
May 30, 2016 15:27
This is still present in some form in 5.3.4f1.
The material change seems to only take effect after the collider has encountered a different collider than the one where the change occurred.
Here's a video I took: https://www.youtube.com/watch?v=x8LWTBRGhMI&feature=youtu.be
When the character collides with a surface, it changes to one of 3 materials:
a) The char is moving uphill, it gets a high friction material (and gravity is removed so it doesn't slide down).
b) The char is on a flat surface, it slows down fairly quickly.
c) The char lands on a hill going down, it should slide down with basically no friction.
The slide happens instead when it hits the first flat surface after going downhill. The second flat surface it comes into contact triggers the normal ground behavior because that's the collider after the flat surface material takes effect.
Zolden
Dec 10, 2014 18:09
I've had this bug too.
This code will not have effect:
public PhysicsMaterial2D matToChange;
void changeMaterial(){
collider2D.sharedMaterial = matToChange;
}
The object will keep acting like its physics material wasn't changed.
Also, if we pre-apply the material in editor, and cahnge its parameters, it will not work too:
void changeFriction(float newF){
matGo.friction = newF;
}
But this will work:
void changeFriction(float newF){
matGo.friction = newF;
collider2D.enabled = false;
collider2D.enabled = true;
}
And this will work too:
public PhysicsMaterial2D matToChange;
void changeMaterial(){
collider2D.sharedMaterial = matToChange;
collider2D.enabled = false;
collider2D.enabled = true;
}
You see? It seems like some kind of refreshing step required to make the physics material change be applied. And we can force that refresh by disabling+enabling the collider component. But this seems rather like a bug.