Problem with event trigger

Hello guys, I’m having a problem with event trigger and I don’t know how to fix.
Basically what I’m doing is this:
I have an interactive map in which you can select countries. Once you click a country the map scales, giving the impression it’s zooming, and it shows some cities. These cities are gameobjects and each one of them has a EventTrigger component attached with PointerEnter and PointerExit, which I’m using to make an highlight effect.
I have 30 cities: 25 of them work and 5 don’t.
I noticed that if I move the icon’s position up or down, at a certain point, the trigger starts to work as if there was some kind of area that doesn’t allow the trigger to do what’s supposed to.

What could it be?

Thanks a lot

First off, DON’T USE EVENTTRIGGERS :smile: they are bulky and overweight and shouldn’t be used for just click events. Better to write a simple script and use the event interfaces like

IPointerClickHandler
IPointerEnterHandler
IPointerExitHandler

Then have your code / action in the code.

As to the positional issue, this is likely due to the graphic area of the GO your EventTrigger is attached to, as the UI system uses (by default) a graphical raycast to test the image component with a users touch, so by moving the image you are altering where the raycast will be detected.
Hope that helps

1 Like

First of all thanks a lot for the answer! I replaced the EventTrigger with the interfaces as you said :stuck_out_tongue:
Unfortunally the same problem persists and while I got that it has to do with the raycast, I didn’t quiet get how to fix it

Oh and by the way I’m using Screen Overlay as render mode

Could you provide a sample project with the issue, or possibly some images to depict your problem?

1 Like

Let’s see if we can fix it with some screenshots, let me know if you need more :stuck_out_tongue:

From the images that is truly baffling, as one of the “not working” buttons is in between the others (from a height perspective.
Is there an issue with altering their height for the non-working one’s to a position that works?

or is it the height of the image it’self that is causing an issues (I expect not as they look the same height).

If that doesn’t answer it, a sample project will be needed of just that screen (possibly not even with the correct art) to see further.

1 Like

Tomorrow I can try to send you a project, thanks a lot for your time btw :stuck_out_tongue:
All the pictures have the same size. If I increase the height of a bugged one, then the pointer works just from a certain point. For example if I make the first bugged picture higher (which works for like the 5% of it), then it works for 10%, 15% and more (based on how bigger it is)

In other words it works like this:

Also I forgot to tell you that I’m setting the position of the icons runtime (to work with all the resolutions) like this:

        private void SetMap (Transform map, int i)
        {
            Rect rect = mapsRectList[i];
            map.position = new Vector2 (rect.x / MAP_SIZE.width * Screen.width, Screen.height - rect.y / MAP_SIZE.height * Screen.height);
            map.GetComponent<RectTransform>().sizeDelta = new Vector2 (rect.width / MAP_SIZE.width * Screen.width, rect.height / MAP_SIZE.height * Screen.height);
        }

where rect is a constant value of the default position of the icon.

Ok here I made a project just to simulate the bug
https://www.dropbox.com/s/e68aqsbm95pxjjg/GUIBug.zip?dl=0

Thanks again :slight_smile:

Found the problem, didn’t take too long. Although best to take your shoes off so you don’t kick yourself too hard :smile:.

Basically, the reason the towers that aren’t working are being overlayed by other UI objects, namely the world panels. It’s nothing to do with the towers themselves, as you can see here:
2353953--159499--upload_2015-10-25_17-16-44.png

To solve this (without having to resize all the worlds RectTransforms), simply add a CanvasGroup to each World. Then when you are zoomed in to one world, turn off “Blocks Raycasts” (the default behaviour of an overlapping panel) on the other worlds.
2353953--159500--upload_2015-10-25_17-24-47.png
So “Blocks” Raycasts ON for the zoomed in world, OFF for the others.
So I’d suggest, adding it to each world with “Blocks Raycasts” off, then turn it on when you Zoom in.

P.S.
I’d recommend using Prefabs for towers and worlds to make you life and management a lot easier :smile:

Hope this helps.

1 Like

Omg thanks a lot your are great! I will fix it now, I couldn’t really fix it alone :smile:
You are my lifesaver :smile:

1 Like

and it works like a charm, thanks again :slight_smile:

1 Like

No worries, happy to help.
Another of the reasons why I run OSS projects like the UIExtensions project and write books and more :smile:

Hoping to do more content in the future

1 Like