Pop-Up Canvas/Panel Not Blocking Raycast to Buttons/UI Below - unity3d

I'm trying to create a pop-up window that will overlay on top of the current canvas and block all interaction with it. Everything I read says to use Canvas Group(s) and/or Graphic Raycaster, but I can't find the magic combination to make that work.
Canvas O is a Screen-Space overlay for typical buttons.
Canvas K is a World-Space canvas for my current UI stuff that I can pan around and whatnot.
Canvas P is my popup which is also an overlay and which I want to block all interaction with both O and K "behind" it. I've put a Canvas group on all 3, I've put a Graphic Raycaster on P, I've selected "Blocks Raycasts" in the Canvas Group of P as well as setting the "Blocking Objects" and "Blocking Mask" to All and Everything. I've put colliders on, and I've made the canvases different Sort Orders for layering. I'm out of ideas. Why won't it block??

Canvas UI objects are drawn in descending order (so that the lowest object under the canvas in the inspector is drawn last and is in front of everything else).
Like this:
Canvas
Text1
Text2 (drawn after Text1)
OverlayImage (drawn after Text1 and Text2, blocking raycasts)
If you add an image UI object to a canvas, drag it to be the lowest object under that canvas in the inspector like in the example above, then expand it so that it takes up the entire canvas, and set the anchors (which control resizing) to expand based on the width and height of the window, that image should always cover the entire canvas. As long as it stays as the lowest GameObject in the inspector hierarchy, it should block events underneath that on that canvas.
I'm not sure about one canvas blocking events on other canvases in the scene, but I would add OverlayImages on all of the canvases, and control whether the OverlayImages are enabled or disabled from canvas P in your example.

Related

Text becomes invisible behind background canvas Unity

I just added 3D Text on my scene and it is invisible on the background of Canvas, that is "Render Mode: Screen Space - Camera". How i can make it visible on background of my canvas?
There are 2 ways to fix this:
Change the Sorting Layer of the obstructing object to be one behind that of the text, or change the Order in layer of the obstructing object to be lower than that of the canvas.
OR
Create a new canvas with a higher Sorting Layer (you may need to create a new one) or Order in Canvas and place the text in the new canvas.
As an example, here I have my normal text in a lower canvas, but I created an overlay canvas for text that absolutely must go above everything else.
I find that the second solution is a better general solution for the issue, as in the first solution you have to change the layers for every object in the scene that might obstruct your text.

How to Create a Blocking Mask in Unity using Image Components?

I'm designing a tutorial for a Unity game and am stuck at what seems like a trivial problem. For every step in the tutorial, I guide the user by hiding everything on the screen except the buttons they need to press. My game hierarchy looks like this.
Button Canvas
Select_Me_Button
Dont_Select_Me_Button
Tutorial Canvas
Mask Group 1
Left Border Mask
Right Border Mask
Up Border Mask
Down Border Mask
Mask Group 2 ...
The TutorialCanvas GameObject has a Canvas component with a higher sorting order than ButtonCanvas. I added GraphicRaycaster Component with Blocking Mask set to everything and Blocking Objects set to None for the TutorialCanvas. However, even though TutorialCanvas renders on top of Button Canvas, I am still able to click through the mask and trigger buttons that are not supposed to be clickable. I was able to block clicks by adding image components functioning as masks to parent objects Mask Group 1 and Mask Group 2 belonging to TutorialCanvas, but this is not desirable, because I need to group the image components to create a mask, and gameobject can only accept 1 image component.
I'm having a hard time imagining this is so hard. I just need one canvas with a mask to block clicks going to a canvas behind it.
Thanks to the help on Unity Forum I solved the issue by creating a single group of masks and positioning them via RectTransform's anchoredPosition component in script.

Unity2D layering multiple canvas'

I have two canvas' set up for my project, one to act as a background and one to hold foreground UI elements. Originally they were set to world space, and I had no problems, but now I am optimizing my game, I must change the space so they adjust to mobile phones. How can I design the canvas' so that one acts in the background and the other in the foreground? I have tried changing the z-pos and other quick fixes I found online but none have worked.
Ok, you have background canvas, sprites and foreground canvas, and background canvas should be behind everything including sprites.
The idea is to render at first only background with one camera, and then render everything with another.
To do that, we should:
Add a layer for background canvas. Change layer of background canvas and children to that layer.
To add a layer, select any gameObject and in top of the inspector you will see:
Click on a dropdown list labeled "Layer" and select "Add Layer". Then create new layer and give it a name:
Select your background canvas and change layer for it and its children. When adding gameObjects, keep in mind that if you add them to background canvas, their layer must be the same as the layer of canvas, otherwise they will be rendered by the wrong camera.
Disable that layer in main camera's culling mask.
Now the camera should no longer render background UI, and it will disappear in the game view.
Add a camera for rendering background UI.
Cameras with higher depth render on top of those with lower depth, so we should set its depth to less than depth of main camera. We should also set its culling mask to only layer for background UI, otherwise all objects on scene will be rendered twice. Copy other setting from main camera. Set main camera's clear mode to Don't Clear or Depth Only to prevent it from erasing background.
Set mode of the background canvas to Screen Space - Camera and drag newly created camera into field "Render Camera" there.
It should work now.

I can not scale my Canvas in unity

I can't scale my Canvas in unity. Where i normally do it, it like this:
I can't scale it or any thing.
As indicated at the top of the RectTransform, values are driven by the Canvas component (or the CanvasScaler component)
According to the Render Mode you have selected, you are able (or not) to change the values. You may want to scale the children of the canvas instead of the canvas itself. If you have problems with designing your UI for multiple resolutions, I advise you to read the documentation page about this problem.
Screen Space - Overlay
The canvas is drawn after all the other cameras. Its dimensions change according to your screen. The scale does not need to be changed.
ScreenSpace - Camera
The canvas is rendered by the given camera, at a given distance from the latter. Its dimensions change according to the camera's rendering settings.
World space
The canvas is a "real" object inside your scene, treated like any other objects (culling apply, ...). In this mode, you can scale the canvas.
Source : https://docs.unity3d.com/Manual/UICanvas.html

How to change canvas position in Unity?

I'm very new in Unity and in GameDevelopment at all. So I've started with Roll-a-Ball tutorial. And now I have a trouble with UI Lesson. When I create Text element Canvas parent creates in strange position.
But in lesson I see that Canvas is near Player object. How can I move it?
If you want to see the canvas fit inside your scene camera's view, change the Canvas's Render Mode to Screen Space - Camera; then drag the Main Camera onto the newly visible Render Camera field in the inspector.
See the bit in your canvas inspector about it being "screen space - overlay"?
That means:
"This render mode places UI elements on the screen rendered on top of the scene. "
And what THAT means, is that you don't have to worry about where the Canvas and child Text show up in your scene view. When you run the game the UI elements will overlay on the background world objects and it'll all be fine.
Source:
http://docs.unity3d.com/Manual/UICanvas.html
It shouldn't matter where the canvas is located, but you can select the child object called 'text' and change the X and Y values to move it around the screen. I hope this helps!