Make pointer ignore target's child?

I’m currently working on the inventory (slot based) for my game, more specifically the tooltip for items. And for aesthetic and style purposes, the items are slightly bigger than the slots they’re in (slots are 80x80, items are 100x100).

However this causes the tooltip to appear prematurely and disappear late. I.e. I can hover the cursor on the gaps between and outside the slots and the tooltip will appear. I narrowed it down to the script in the parent reacting to the child.

How can prevent this? I’ve been looking all day.

The script uses the “OnPointer” enter and exit methods, which call methods in the tooltip GameObject’s script that changes its “Canvas Group” alpha value.

If you want all mouse interactions based on the parent and not the child, then you should uncheck the “raycast target” box on the child (on every image/text/similar component on the child). That will cause all mouse actions to “pass through” it as if it weren’t there.

1 Like

Would that prevent me from interacting with the child if I’m trying to? For example right clicking a potion to use it. Just curious.

If so I could easily re-check it in code just before attempting to do something with the slot’s child, or interact with the parent but the affect the child through code.

Unity has no way of knowing what you are “trying” to do. If you want your game to respond differently in two different cases, then at minimum you need to be able to describe the difference between those two cases in terms of actions, not intentions.

If you want the mouse to interact with part of the object, but not the whole thing, you could uncheck “raycast target” on the main image but add a second image “raycast target” turned on that covers only the portion that you want the mouse to interact with. That second image can be 100% transparent if you want, so it will be invisible but still interactable.

2 Likes

Cheers! A fresh pair of eyes is just what I needed. :slight_smile: