Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnmaskRaycastFilter not working anymore #29

Closed
Heurazio opened this issue Sep 4, 2023 · 2 comments
Closed

UnmaskRaycastFilter not working anymore #29

Heurazio opened this issue Sep 4, 2023 · 2 comments
Assignees
Labels
bug Something isn't working released on @main

Comments

@Heurazio
Copy link

Heurazio commented Sep 4, 2023

It seems that the UnmaskRaycastFilter is no longer working. The Button receives no events even though the IsRaycastLocationValid function behaves correctly.

To Reproduce
Steps to reproduce the behavior:

  1. Unity 2022.3.2f1
  2. Create a new scene
  3. Add the UI > Unmask > Tutorial Button
  4. Try to click the button with the default settings => Does not work

Expected behavior
The button should receive the events

Screenshots
image
It is not possible to provide a screenshot of it not working

Environment (please complete the following information):

  1. Unity 2022.3.2f1
  2. Unmask 1.4.1
  3. URP
  4. InputSystem/EventSystem

Not sure what I'm doing wrong. I already checked the IsRaycastLocationValid and this is working correctly. I also tried different camera settings. The "area" is detected correctly, but the ray is not passing through. Any help is welcome.

@Heurazio Heurazio added the bug Something isn't working label Sep 4, 2023
@snoopyuj
Copy link

Hi, I'm new here. I had the same issue today, and I believe the problem was with the UnmaskRaycastFilter being on the wrong object. I moved the component from "Screen" to "Unmasked Panel," and it worked quite well.

If this solution is accurate, here is an edited version of MenuOptions_UIUnmask to ensure the correct objects are created:

using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

namespace Coffee.UIExtensions.Editors
{
    internal class MenuOptions_UIUnmask
    {
        [MenuItem("GameObject/UI/Unmask/Tutorial Button")]
        private static void CreateTutorialButton2(MenuCommand menuCommand)
        {
#if UNITY_2021_2_OR_NEWER
            const string menuItemName = "GameObject/UI/Legacy/Button";
#else
            const string menuItemName = "GameObject/UI/Button";
#endif
            EditorApplication.ExecuteMenuItem(menuItemName);
            var button = Selection.activeGameObject.GetComponent<Button>();
            button.name = "Tutorial Button";

            var unmaskedPanel = CreateUnmaskedPanel(AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd"), Image.Type.Sliced);
            var unmask = unmaskedPanel.GetComponentInChildren<Unmask>();
            unmask.fitTarget = button.transform as RectTransform;
            unmask.fitOnLateUpdate = true;

            Selection.activeGameObject = button.gameObject;
        }

        [MenuItem("GameObject/UI/Unmask/Iris Shot")]
        private static void CreateTransition(MenuCommand menuCommand)
        {
            var unmaskedPanel = CreateUnmaskedPanel(AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Knob.psd"), Image.Type.Simple);
            unmaskedPanel.name = "Iris Shot";
            Selection.activeGameObject = unmaskedPanel;
        }

        [MenuItem("GameObject/UI/Unmask/Unmasked Panel")]
        private static GameObject CreateUnmaskedPanel(MenuCommand menuCommand)
        {
            return CreateUnmaskedPanel(AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd"), Image.Type.Sliced);
        }

        private static GameObject CreateUnmaskedPanel(Sprite unmaskSprite, Image.Type spriteType)
        {
            EditorApplication.ExecuteMenuItem("GameObject/UI/Panel");
            var mask = Selection.activeGameObject.AddComponent<Mask>();
            mask.showMaskGraphic = false;
            mask.name = "Unmasked Panel";
            mask.GetComponent<Image>().sprite = null;

            EditorApplication.ExecuteMenuItem("GameObject/UI/Image");
            var unmask = Selection.activeGameObject.AddComponent<Unmask>();
            unmask.name = "Unmask";
            unmask.transform.SetParent(mask.transform);
            unmask.GetComponent<Image>().sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd");

            mask.gameObject.AddComponent<UnmaskRaycastFilter>().targetUnmask = unmask;

            var image = unmask.GetComponent<Image>();
            image.sprite = unmaskSprite;
            image.type = spriteType;

            EditorApplication.ExecuteMenuItem("GameObject/UI/Panel");
            var screen = Selection.activeGameObject.GetComponent<Image>();
            screen.name = "Screen";
            screen.sprite = null;
            screen.color = new Color(0, 0, 0, 0.8f);
            screen.transform.SetParent(mask.transform);

            return mask.gameObject;
        }
    }
}

Hoping it's not too late to help :)

github-actions bot pushed a commit that referenced this issue Oct 25, 2023
## [1.4.2](1.4.1...1.4.2) (2023-10-25)

### Bug Fixes

* UnmaskRaycastFilter not working anymore ([14ab505](14ab505)), closes [#29](#29)
@github-actions
Copy link

🎉 This issue has been resolved in version 1.4.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released on @main
Projects
None yet
Development

No branches or pull requests

3 participants