Search Unity

Bug Bug #1331901: ProBuilder (5?) no longer properly cleaning up its Materials array when deleting faces

Discussion in 'World Building' started by dgoyette, Apr 26, 2021.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    This seems like a regression. If a ProBuilder object has multiple materials assigned to it, it generally automatically manages the MeshRenderer's Materials list, adding and removing materials based on what has been assigned to the faces. But now, if you delete the last face of a PB object that has a given material assigned to it, it no longer deletes that material from the OB object. Instead, it complains about having too many materials for the number of submeshes: "This renderer has more materials than the Mesh has submeshes. Multiple materials will be applied to the same submesh, which costs performance. Consider using multiple shader passes."

    For example, here's a PB objects with two materials. Mat2 is the green material, assigned just to that top face. Looks fine.

    upload_2021-4-26_12-44-53.png

    Now delete that green face (Mat2) and you get this:

    upload_2021-4-26_12-45-22.png

    It used to be that deleting the green face would remove Mat2 from the materials array. But that doesn't seem to work anymore. And manually cleaning this up seems to have a strong likelihood if just messing up all of the materials assignments on the remaining faces.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    QA replied and told me that this was by design:

    "It is valid that a MeshRenderer have multiple Materials for a single submesh, despite the warning. Since we can’t guess the user intent, we will only ever append to the MeshRenderer Materials."

    That reply doesn't make a lot of sense to me. But once you get into this situation, I don't see how you can recover. Are we expected to manually delete the materials from the Materials array on the renderer? Because if so, that causes other problems, where the remaining faces are likely to change their material association.

    If this behavior is by design, how do developers recover from this?
     
  3. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    552
    > Are we expected to manually delete the materials from the Materials array on the renderer? Because if so, that causes other problems, where the remaining faces are likely to change their material association

    That's a valid point. If I remember correctly, we changed to this new method because we had requests to enable the workflow of multiple materials on a single submesh. That's a pretty specific use, so maybe we should re-enable the behavior of managing the materials array by default and expose the hands-off approach as a preference.
     
    dgoyette likes this.