- Home /
Canvas Disabled but UI elements still block Raycasts
I have this hierarchy of Canvases Canvas_Parent
- UI Elements
- Canvas_Child
- - UI Elements
- Canvas_Child
- - UI Elements
In order to turn them all off at once I disable the Canvas Component on Canvas_Parent. However, the UI Elements under Canvas_Child continue to block Raycasts while the ones directly under Canvas_Parent do not.
Pretty Frustrating
All of the UI Elements within the hierarchy do not block Raycasts until the Canvas_Parent component is enabled for the first time
How can I ensure no UI ELements in that hierarchy block Raycasts when I disable Canvas_Parent component?
Note: I can't use SetActive on the gameobject to just close down the full hierarchy for performance reasons.
Answer by Knights_user · Mar 09, 2020 at 11:23 AM
Try disabling "Graphic Raycaster" component on Canvas.
Answer by LOSTSOUL86 · Jan 06, 2020 at 05:08 AM
Hi maybe this can help. If you want to disable all children along with parent, I did by
parent.setActive(false);
And later to enable.
parent.setActive(true);
Then nothing is blocking raycast. In your case you disabling 1 canvas so other canvases are still active.
Maybe you should consider structure like:
popUpMenu (no canvas - just control script)
- Menu1 (with canvas)
Menu2 (with canvas)
Menu3 (with canvas)
in control script you just put:
public GameObject menu1;
public GameObject menu2;
public GameObject menu3;
And then popUpMenu is always active to keep script active and to keep children accesible and depending on action you just do menu1.setActive(true).... menu2.setActive(false).... etc you can turn on or turn off any of them at any time.
Appreciate your answer, but I'm avoiding using gameobject.SetActive() as it is much worse for performance. Unity recommend disabling the component - in this article on UI performance at number 6 - rather than using SetActive.
I'll edit my question to include this bit of information since I missed it. Sorry about that.
Hi. But it's still the same problem. Game objects can have game objects in child. But components do not have children. Switching off component in one game object does nothing to its children. Still you need to get reference to game objects. And then for example Canvas canvas1 = menu1.GetComponent<Canvas>();
And later canvas1.enabled = false; Do the same for menu2/canvas2 and menu3/canvas3 Components dont have children. You need to switch off component in every game object to achieve what you need.
Hi. I see, I misread your answer. I thought you were saying use SetActive on the parent gameobject in order to turn off the entire heirarchy.
I was hoping that there is some kind of parenting happening since the blocking doesn't happen until the first time I enable that parent canvas.
Storing a reference to each Canvas would technically work, but it isn't a route work want to take as it requires a major overhaul to the existing code base.
Answer by AntonioPena · Mar 09, 2020 at 11:51 AM
hi, adding a CanvasGroup component to the Canvas_Parent and change property .BlocksRaycasts to false works for me. Remember to change this property to true when you activate the canvas component again.
hope it helps
Antonio
Answer by aoun111 · Mar 14, 2020 at 10:15 AM
Add a canvas group and disable the checks interactable and blocks raycast.
Your answer
![](https://koobas.hobune.stream/wayback/20220612221104im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Click on Canvas in a render texture 0 Answers
Trying to cast a ray towards a canvas but an invisible copy(?) of the canvas is blocking the way. 1 Answer
Can't interact with buttons in a UI Canvas in World Space Render Mode. 0 Answers
Help with Raycast on Render Texture 0 Answers
UI Buttons visible but not clickable when using two canvases. 3 Answers