Search Unity

Should it be possible to edit a PhysicsMaterial asset at runtime and see the change live?

Discussion in 'Physics' started by Xarbrough, Sep 12, 2019.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    518
    I have a PhysicsMaterial2D applied to a few colliders in my scene and tried to tweak the friction and bounciness values at runtime. However, I quickly noticed that the values are not reflected in the live simulation. Instead I needed to disable and re-enable all colliders or restart play mode to see the changes.

    I understand that this may be a limitation of communicating with the physics middleware, but it could also be a bug, so I wanted to ask in the forum.

    If this is intended behavior I would like to suggest to show a small info text on the PhysicsMaterial2D inspector when in play mode, e.g. "Changes made in play mode will only be applied when affected colliders are toggled.".
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,968
    No, this isn't a live asset that is read each simulation step. If you change it you'll need to reassign it, no need to disable/enable the collider.

    It's a frustrating limitation that would require a significant change to Box2D to get this working. So far it's not been a high priority but I understand it's kind of annoying.

    In the meantime I'll look at updating the docs and making the behaviour more obvious.
     
    Xarbrough likes this.