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
1.97k stars 261 forks source link

[v1] Masked images disappear on resize if there are images using the normal Unity mask #117

Closed SvenRH closed 1 week ago

SvenRH commented 3 years ago

Describe the bug Softmaskable images disappear when game is resized when there are are images using the unity mask in the scene.

To Reproduce Steps to reproduce the behavior:

  1. Create new project, add Softmask and Demo
  2. Open Soft Mask Demo
  3. Resize Game View
  4. masked images disappear

If the images using the 'normal' Unity mask are removed, everything seems to be fine.

Expected behavior SoftMask should work when there are Unity Masks used in the scene.

Screenshots image

Environment (please complete the following information):

SvenRH commented 3 years ago

The issue seems to be that the RenderTexture is recreated on resize, but the new Texture isn't applied to the SoftMaskable.

A possible fix would be to add the softMaskBuffer to the _effectMaterialHash calculation, but it seems like it would be a better idea to just set the Texture outside of MaterialCache (seems like overkill to recreate the material just for that).

Runelink2 commented 1 year ago

Is there any update on this? The fix mentioned sounds nice but I'm not sure how to apply it.

NotGeniusy commented 1 year ago

I made a script that disables and re-enables SoftMasks to refresh them. It worked for me. Just place this script to every GameObject with SoftMask.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Coffee.UISoftMask;

public class SoftMaskFixer : MonoBehaviour
{
    private SoftMask softMask;

    private List<GameObject> childs = new List<GameObject>();

    private void OnRectTransformDimensionsChange()
    {
        if(softMask == null)
        {
            softMask = GetComponent<SoftMask>();

            foreach(Transform child in transform)
            {
                childs.Add(child.gameObject);
            }
        }

        if(gameObject.activeInHierarchy)
        {
            StartCoroutine(Fix());
        }
    }

    private IEnumerator Fix()
    {
        foreach(GameObject child in childs)
        {
            child.SetActive(false);
        }

        softMask.enabled = false;

        yield return new WaitForSeconds(0.01f);

        softMask.enabled = true;

        foreach (GameObject child in childs)
        {
            child.SetActive(true);
        }
    }
}
mob-sakai commented 1 month ago

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

mushakushi commented 1 week ago

I'm able to reproduce this issue on 2.2.0 with Unity version 2022.3.16f. There are some instances where the image flickers before disappearing when the canvas is actively being resized.

mob-sakai commented 1 week ago

Thank you for your reporting!

mushakushi commented 1 week ago

Does it occur only in the editor?

Yes and regardless of if playmode is enabled.

Can I attach videos or gifs?

https://github.com/user-attachments/assets/3f733bc2-a361-45b2-a737-8adeb9a0eeb5

Thank you for your quick support!

mob-sakai commented 1 week ago

@mushakushi I created a new issue: #184