UI Button doesn't disappear when deactivating parent in hierarchy - unity3d

I'm trying to write a simple main menu page with this hierarchy:
MainMenu (an empty game object)
↳ Canvas
↳ PlayButton (a TextMeshPro Button)
I want the button to deactivate the 'MainMenu' object in the hierarchy when clicked, thus hiding its Canvas child and the Button along with it. To do this, I'm providing the MainMenu object reference to the Button's OnClick() callback and calling 'GameObject.SetActive' to false when clicked.
My problem is that when I click the button, the MainMenu hierarchy get grayed out in the editor but the Button sticks around with its yellow Highlighted color shown. It does disappear if I change the display resolution while still in Play mode (maybe forcing a refresh?), but I can't figure out why deactivating the MainMenu wouldn't make it refresh in the same way.
I've tried calling SetActive(false) on the PlayButton and the Canvas themselves- I also tried setting enabled = false on them, but the Button appearance behaves the same. From everything I've read, calling SetActive(false) should hide whatever gameObject I call it on, so I can't figure out what I'm missing.

Alright, found my own mistake. The Camera's Clear Flags setting was Don't Clear, so even calling Destroy(gameObject) on it didn't remove it from the screen.
Setting the Camera to use ClearFlags: Solid Color fixed the problem.

It looks to me like you have a button in your grid that is displaying. When the game is playing, after you click to turn off the button, go to the scene tab, click the yellow button and see where that object is.
If in doubt (For testing purposes only) delete the button on click and if you see something else then it is obviously not that button.

Related

Some Objects in Prefab instance not response the click event

I have multi-numbers browser windows in the Unity app, the newly opened window will popup to the front.
I want to call the clicked window to the front, so I attached a Hierarchy script.
public class Hierarchy : MonoBehaviour, IPointerDownHandler
{
[SerializeField] private RectTransform topWindow;
// Set clicked object to top
void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
{
// Print debug message to the console
Debug.Log("Object clicked: " + eventData.pointerCurrentRaycast.gameObject.name);
topWindow.SetAsLastSibling();
}
}
But windows only response to the front when it's title bar be clicked, click else where doesn't work. I checked it only detect click event when the title bar be clicked, but not detected click event when click browser area.
Here is the hierarchy in the Prefab, BrowserWindow is the entire are of the window. BrowserBackground is the dark background wraps browser. Browser2D is the Prefab for rendering browser. ControlButtons is the title bar include the page name, close button and detail button.
Anyone can figure out what is this problem comes from?
Try turning off the Raycast Target of an Image that is not related to a click event.
Unity Event takes into account the before/after relationship of objects.
Unity Event responds to Image and Collider.
Unity Event does not respond when Raycast Target is turned off.
If it does not work, it may work better if you use a click-only transparent Image for the foremost side.
BTW: Transparent images are heavy. You can solve this problem by turning off "Cull Transparent Mesh".

Unity UI Resume Game button is unclickable

So i have been trying to create a pause menu for my project, however the resume button is un-clickable (the same i believe for another button on this menu). The event system does not show anything when hovering over this button or attempting to click it.
Screenshot of Event System not showing button object
The button itself is set to interact-able and has the button's image as it's target graphic. The canvas it is also placed on also has the Graphic Ray-caster component attached. I also do not believe that there is any UI object covering the button preventing it from being clicked.Screenshot of Pause Menu UI as seen from scene view to show no blocking objects I am making use of the first person character controller starter asset by unity as well as the new input system.
I am unsure as to what could be causing this, I have also tried locking the cursor of the starter asset inputs.
Any advice would be greatly appreciated.

Button obscured by another Button can't be pressed

There are 2 buttons - Button A and Button B.
Button B is situated on top of Button A.
Button B has it's Button Component removed.
I want the user to be able to click on Button A even though Button B obscures it.
How can I achieve this?
Not sure What is your question but if you want to click start button while air button is above it. you should disable the option on button called Interactable and also uncheck the toggle in image component of that button called Raycast Target. and that will do it.
Of course Button B button will block the one underneath it. Because Image component and Text and/or other Image component that button has blocks raycast to the button underneath of it.
You can do one of the following:
Remove your Button B button, because if it's not doing anything and actually interferes with a behavior you want then why have it in the first place? Think about it
Uncheck Raycast Target in your Button B button's Image component
Disable Image component of Button B button altogether
Thinking about first item on the list will benefit you greatly.
If you want a solution then use second or third option on the list, but bare in mind that unchecking Raycast Target or disabling Image component of your "Air" button still leaves an Image and/or Text as a child of aforementioned button that CAN and WILL block raycast to your Button A button.

Unity new UI button click able outside of button area, non clickable over button area

I have created new UI button in empty scene,
Whenever I click on button its not click-able , but when I take cursor slightly above the button area and click, it gets clicked.
I guess Something like offset problem occurring?? Any fix to that?
NOTE I have tried creating new scene same result
,also created new project though Same result.
Did you check the EventSystem gameObject, it displays which UI element you are hovering, and other useful information.
After lot of trial and errors, reinstalling Unity did the job

How to make a button in android and make it invisible

I want to have a button which should not be visible but when clicked onclick should be executed..
I have tried making
Button button;
1)button.setVisiblity(4);//it made it invisible but onclick was not working
2)In the layout xml i have attached android:visibilty="invisible" //but it made it invisible
Remove the visibility bit and use the following instead.
button.setBackgroundColor(Color.TRANSPARENT);