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] Soft mask problem with default mask and resolution change #157

Closed Andrea332 closed 2 months ago

Andrea332 commented 1 year ago

I have this strange problem when i'm using the unity default mask and the soft mask at the same time, for example when i change resolution of the game the soft mask and everything below it disappeard.

Steps to reproduce the behavior:

  1. Open a new Unity scene
  2. Create 2 identical Canvas with an image in it and another image inside the image itself image
  3. On one canvas uses the soft mask components and on the other use the default unity mask
  4. Now change the resolution and you will se the soft mask disappeared
  5. It returns working when you disable and re enable the soft maks component

Using a unity default mask should not impact on other soft mask in the scene or prefab

Andrea332 commented 1 year ago

I presume the problem is when OnRectTransformDimensionsChange is called in the soft mask component

colindefais commented 1 year ago

Hey, I have got the same issue in my project.

I have discovered that de-activating and re-activating a parent of the broken SoftMask GameObjects fix them.

So I have just made a dirty workaround with the following script. It simply de-activate and re-activate its own gameObject when a RectTransformDimensionsChange happen.

Of course you have to put this Script on a parent of the broken SoftMask GameObjects.

using UnityEngine;

[HelpURL("https://github.com/mob-sakai/SoftMaskForUGUI/issues/157#issuecomment-1691486145")]
public class ReActivateOnResize : MonoBehaviour {

    void Start() { }

    void OnRectTransformDimensionsChange() {
        if(isActiveAndEnabled) {
            gameObject.SetActive(false);
            gameObject.SetActive(true);
        }
    }

}

This is not perfect:

Of course instead of using my script you can replace all default Unity Masks by SoftMasks, but in my case I prefer using SoftMasks only when necessary (to avoid putting SoftMaskable components everywhere).

renee0506 commented 1 year ago

I resolved this issue by adding

protected void OnRectTransformDimensionsChange()
{
   OnValidate();
}

to SoftMaskable.cs

mob-sakai commented 2 months ago

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