Search Issue Tracker

Fixed in Unity 5.2.0

Votes

6

Found in

4.3.0f4

Issue ID

577228

Regression

No

Physics material has no effect when changed from code

Physics2D

-

-

Priority: 3Not yet prioritized for a release

-

Severity: 3Secondary functionality broken

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)

  1. 17fc68b4e80692947b605e3f8b9dedb5?d=mm

    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.

  2. 5b38c746b71c7b0b2e118aaae62a2ccb?d=mm

    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.

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.