mob-sakai / SoftMaskForUGUI

Enhance Unity UI (uGUI) with advanced soft-masking features to create more visually appealing effects!
https://github.com/mob-sakai/SoftMaskForUGUI
MIT License
2.04k stars 268 forks source link

[v1] I tried changing properties of material using softmaskable but the gameobject properties stay the same #166

Closed raaan127 closed 2 months ago

raaan127 commented 4 months ago

I tried to change property of a material that attached into Image component I tried on runtime and nothing happen so I change the property on editmode, the original material's properties is changed but the softmaskable material property stay the same.

ảnh ảnh

mob-sakai commented 4 months ago

Thank you for your reporting!

This behavior is a specification of the instantiated material and will be reproduced in Mask as well as SoftMask. If RawImageTilingOffset component directly modifies the material parameters of graphic.material, the changes will not be reflected in the instantiated material.

As a workaround, RawImageTilingOffset component needs to implement the following.

  1. Implement IMaterialModifier interface. GetModifiedMaterial method as follows:
    • Create a new material instance from the baseMaterial. Cache the material instance to avoid unnecessary creation.
    • Use material.Set*** method to modify the parameters of the instantiated material.
    • Try to keep the implementation of the GetModifiedMaterial method as low load as possible.
  2. Call graphic.SetMaterialDirty method when Scale or OffsetSpeed is changed, or in OnValidate method.
mob-sakai commented 2 months ago

Please try v2: https://github.com/mob-sakai/SoftMaskForUGUI/releases/tag/v2.0.0