Graphic Raycasting doesnt work on all children canvases
I have an Inventory system with Slots in it. All the Slots are children of Slotholder which has a Graphic Raycast component. I use this component in a child GameObject of the Slot, which is called TriggerEvent to capture events to move stuff around the inventory. Now i wanted to add a tooltip which i can close by clicking anywhere on the screen. To do that i added a screenwide panel behind the tooltip window that will play a role of a giant "button". And again, to capture clicks i added new script with IPointerDownHandler which disables the window. In Unity documentation i read that it is enough to have Graphic Raycast on the root object in order to capture all the events below. Which doesnt happen. I need to add to that giant "button" another Raycast component, which is ridiculous considering that i have 100 slots.
This is what TriggerEvent has:
Rect Transform
Canvas Renderer
Image (blank with Raycast Target checked)
Script with all the interfaces
This is what PaneltoCloseToolTip has:
Rect Transform
Canvas Renderer
Image (blank with Raycast Target checked)
Script with the interface IPointerDownHandler
Canvas
and to make it work > Graphics Raycaster
Position in the Hierarchy:
Slotholder(With Graphic Raycaster)>Slot>Tooltip(blank GO)>PaneltoCloseToolTip(also with With Graphic Raycaster)
Slotholder(With Graphic Raycaster)>Slot>TriggerEvent
What am i doing wrong?
Answer by AQAGA · Mar 06, 2020 at 05:26 PM
could someone at least specify if it is ok to have 100 raycasters if noone knows the answer?
Answer by carlo_unity237 · Apr 13, 2021 at 12:59 PM
If I understood right, your gameobject that doesn't register input has it's own canvas, in which case it does indeed need graphics raycaster. Canvas and graphics raycaster go hand in hand. You are also saying you have hundreds of these objects, so it sounds like you need to remove these canvases, and have canvas + graphics raycaster in a parent object, to handle the childrens. Having several Canvases is fine and good, but a hundred sounds like too much.
Your answer
Follow this Question
Related Questions
Dragging child item in Horizontal Layout Group 0 Answers
ui Buttons rendered on camera 0 Answers