Search Unity

Event System not recognizing Image Raycast Target

Discussion in 'UGUI & TextMesh Pro' started by thegreatmiasma, Jun 10, 2022.

  1. thegreatmiasma

    thegreatmiasma

    Joined:
    Mar 27, 2016
    Posts:
    48
    I load spriteatlases via an addressables pipeline and then load them to a canvas. Everything has been working fine but now the event system is failing to recognize some loaded images. The appear on screen and their components indicate they should be receiving raycasts, but when viewing the event system feed back it does not show some images as being hovered/raycast hit. Ive tried forcing a canvas update as well as a recttrans update but that does nothing. Sometimes if I reposition that particular image's place in the hierarchy I can get it to register in the Event System window but it isn't consistent. Any ideas on why this might be occurring? Oh, it works in Unity 2021 but not 2022. Both silicon.
     
    Last edited: Jun 10, 2022
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Run it, press pause and study the scene.

    - is the thing where you think it is? enabled?

    - is nothing else inadvertently in front of it?

    Are you hitting ANYTHING with your raycast?
     
  3. thegreatmiasma

    thegreatmiasma

    Joined:
    Mar 27, 2016
    Posts:
    48
    I’ve done pretty thorough testing that covered all that. The fact that it works fine in 2021 but not 2022 tells me the pipeline I built is fine. The only reason I switched to 22 was to use the memory management profiler, the game should be published before 22 is needed. Would like to know why the behavior exists but I’ve got other things to do.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    I'll move your post out of the 2D forum as it has nothing to do with any 2D feature and into the UI forum which is the subject of your post.
     
  5. thegreatmiasma

    thegreatmiasma

    Joined:
    Mar 27, 2016
    Posts:
    48
    Since it seams to have to do with possible version bugs is there a better forum than UI?
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    This line:

    ... really makes me think there's something else in your scene getting in the way of things.

    What about pausing the game when this happens, then ripping out the addressable versions that were loaded and instead dragging fresh prefab instances in at runtime. Does that work?

    What about piecemeal tearing apart the addressable thing after it is loaded, add buttons to it at runtime, see that is and isn't responsive?
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    It's the target/subject of your post which should determine the place to post it. Here you're talking about an issue using Images/Canvas and the Raycast EventSystem. This is entirely the UI system. Whether it's something you're doing or if it's a bug in those packages/specific version of Unity doesn't change where to post it TBH.
     
  8. thegreatmiasma

    thegreatmiasma

    Joined:
    Mar 27, 2016
    Posts:
    48
    By moving I mean just a few pixels and this usually doesn't work. Also, if I change its position to the front most position in the hierarchy it will work. I've tried disabling everything else in the canvas and that does nothing. The event system shows realtime feedback regarding what the raycast is currently hitting and what it shows being hit are below the missed items in the inventory, same sorting layer as well.

    The game switches from 2d scene to 2d scene each comprised of image layers. The basic building of every scene is the same. I had replaced one of the component types image reference to a non addressable sprite atlas and this allows that component to work. However, other items in the scene still use the addressable reference and are detected by the event system. In addition every item in other scenes right before and after the affected scenes work as intended. It seems random but it's always the same scenes that malfunction, but again, those scene contain nothing different. I've checked the scenes that proceed the problematic scenes but find no consistencies in them that would point to them as a problem. And again, it works fine in 2022. My only thought now is that somehow the image and physics systems loads on screen before the image physics information loads which is why I was hoping a refresh or canvas reload would work.
     
  9. unity_ctg0ujCJYRi52g

    unity_ctg0ujCJYRi52g

    Joined:
    Jun 1, 2020
    Posts:
    11
    Have a similar issue in 2021.3.4LTS

    PointerEventData eventData = new PointerEventData(EventSystem.current);
    var raycastList = new List<RaycastResult>();
    EventSystem.current.RaycastAll(eventData, raycastList);
    Debug.Log("raycast List count is: " + raycastList.Count);
    foreach (var item in raycastList)
    {
    Debug.Log("raycast hit is: " + item.gameObject.name);
    }

    If the image is on root gameObject it is detected.
    If the image is on the child gameObject it is not detected unless:
    - when placed at the bottom left corner, sticking outside of the screen (negative x, negative y)

    By the way:
    EventSystem.current.IsPointerOverGameObject()
    is detecting the GO correctly.
     
    Last edited: Jul 14, 2022
  10. Baschti-aus-s

    Baschti-aus-s

    Joined:
    Jan 6, 2020
    Posts:
    9
    Did anyone get some further information here?
    I'm facing the same issue as descriped by unity_ctg0ujCJYRi52g (using Unity 2021.3.19f1):

    EventSystem.current.RaycastAll(eventData, raycastList) will not detect images in child gameObjects.
    I have added a GameObject with a BoxCollider behind this image, just to check if OnPointerClick gets fired and it won't. So in general, the eventsystem is aware of the image, only RaycastAll won't report it.

    When I add an additional button component to the child GameObject with the image, RaycastAll will report it.

    Pretty odd behavior.

    Edit01:
    I try to use the Graphic Raycaster component of the canvas and call GraphicRaycaster.Raycast(PointerEventData, List<RaycastResult>) with the exact same behavior. So at least this works as expected, since the RaycastAll method "Raycast into the scene using all configured BaseRaycasters."

    Edit02:
    Got a little work arround that works for me at the moment:
    I called the RaycastAll method at the moment i received Input.GetMouseButtonUp(0).
    Instead of directly calling RaycastAll, I start a coroutine to wait until next update and than i get the expected RayResult from RaycastAll. As I said, works for me at the moment, but still seems to be odd.

    Code (CSharp):
    1. IEnumerator Wait(Vector3 position)
    2.     {
    3.         yield return null;
    4.         PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
    5.         eventDataCurrentPosition.position = position;
    6.         L_RayResultsOfClickPosition = new List<RaycastResult>();
    7.         EventSystem.current.RaycastAll(eventDataCurrentPosition, L_RayResultsOfClickPosition);
    8.         Debug.Log("RaycastAll results: " + L_RayResultsOfClickPosition.Count);
    9.     }
     
    Last edited: Mar 6, 2023
    Thorax- likes this.
  11. thegreatmiasma

    thegreatmiasma

    Joined:
    Mar 27, 2016
    Posts:
    48
    I ended up rolling back my Unity version. Last time I checked a more recent Unity version it was still having this issue though.
     
  12. Thorax-

    Thorax-

    Joined:
    Feb 10, 2021
    Posts:
    23
    Thanks for sharing your experience. I was also struggling with this for so long.
    So without waiting and using RaycastAll right away would detect only 50% of my UI objects.
    I tried waiting for a frame and then RaycastAll returned more UI elements but still not all.
    After waiting for 2 frames RaycastAll would finally detect all the UI elements i was clicking on.
     
  13. Xlebopechka

    Xlebopechka

    Joined:
    Jul 9, 2021
    Posts:
    1
    I solved a similar problem by unchecking IgnoreReversedGraphics in Canvas/Graphic Raycaster. Maybe this will help you.
    Снимок.PNG
     
  14. koxlox

    koxlox

    Joined:
    Dec 5, 2018
    Posts:
    2
    Unity is bullshit. Probably your problem is that your object lies too deep. For example: i got some fields to drop items on like inventory/hands/tradewindow/etc and they have nothing in differ as inventory has its parent without anything attached to it except one script and hands have their parent with nothing attached to it at all, all of em got their Image script, but raycastall doesn't see lefthand/righthand and perfectly sees inventory. But if you attach image script to lefthand/righthand parent, it will see it too. Screw the day I met this engine