Sometimes, Physics materials values need to be update at runtime to refresh material to make it work

Hello,
I have a bug on Unity 2019.3.15f1 which appear sometimes.
I have a physic material on my player which all values are zero and combines are average.
I have another material with same values on wall.
The goal is to make the player not stuck in wall when fall.
It work but sometimes I have the bug which make the PLAYER material value are not applied at runtime then I have to change the values of the material and then back them (at runtime too) and then it work.
It’s not only friction bug, if I put 1 of bounciness, player not bounce while I not refresh material values (runtime).

If I build the game with the bug, I always have this bug when playing.
The bug not require specific condition, it appear sometimes on multiple project with this version of unity.

If in editor I dupplicate the material and apply the copy to the player, it solve the bug but it will come back in future.

1 Like

I can confirm this is happening in version 2020.3.34f1. My objects randomly started exhibiting different friction behavior, and editing the material in the editor while playing would fix it. Just as you said, duplicating the physics material and reapplying it solved the issue.

Same issue on 2021.3.14f1. I almost gone mad trying to figure out where this was coming from.

I ran into this bug in Unity 2021.3.21f1 and was able to ‘solve’ it by reapplying the material on Awake.

public class PhysicMaterialUpdater : MonoBehaviour
{
    private Collider collider;

    // Start is called before the first frame update
    void Awake()
    {
        collider = GetComponent<Collider>();
        if (collider == null)
        {
            Debug.LogError($"No Collider component found on {name}.");
            return;
        }

        if (collider.sharedMaterial == null)
        {
            Debug.LogError($"No Physic Material found on {name}.");
            return;
        }

      
       collider.material = new PhysicMaterial()
       {
           dynamicFriction = collider.sharedMaterial.dynamicFriction,
           staticFriction = collider.sharedMaterial.staticFriction,
           bounciness = collider.sharedMaterial.bounciness,
           frictionCombine = collider.sharedMaterial.frictionCombine,
           bounceCombine = collider.sharedMaterial.bounceCombine
       };
    }
}