Unity 4.6: How to disable ugui object so that you can click things behind it?

Hi,

I am trying to figure out how to click “through” a disabled ugui object. At the moment, things behind the disabled object cannot be clicked.

Here is an example setup:

  • Create ugui panel #1. Put a button in panel #1 that prints “YOU CLICKED ME!” when clicked.
  • Create ugui panel #2. Put a button in panel #2 that calls panel#2.SetActive(false) when clicked.
  • Put panel #2 over top of panel #1 (so you can’t see panel #1 at the start).

Now, when you click the button in panel #2, panel #2 disappears and you can see panel #1 and its button; however, you cannot click the button in panel #1. It is as if panel #2 is still obscuring the ability to click through to panel #1.

Does anyone have any insight on this? How can I hide panel #2 AND allow clicking through to panel #1?

Thanks!

I did exactly as you said and it worked for me.

See the image below, it shows the step by step output.

And here’s the test code:

public class UIClickTest : MonoBehaviour {

	public void ButtonOneClicked()
	{
		Debug.Log("Button One Clicked");
	}
	
	public void ButtonTwoClicked()
	{
		Debug.Log("Button Two Clicked");
		GameObject.Find("Panel#2").SetActive(false);
	}

}

The two functions are attached to each of the buttons. You can also see the structure of UI elements in the hierarchy window.

Wondering why it didn’t work for you.

Setting the panels up as per my original post will actually work fine; however, I’ve reproduced the originally described problem by setting the panels up a little differently …

  • Same: Create ugui panel #1. Put a button in panel #1 that prints “YOU CLICKED ME!” when clicked.
  • New: Create ugui panel #2. Inside panel #2, create a panel #3 with a button that calls panel#2.SetActive(false) when clicked.
  • Same: Put panel #2 over top of panel #1.

Now, here is where things get interesting. Add a Vertical Layout Group to panel #2, add an image as a “source image” for the Image component of panel #3, and make the Image component of panel #3 inactive (by unchecking the box beside it in the Unity IDE).

When I set things up like above, now I cannot click through to panel #1 when panel #2 is SetActive(false). Strange …

If I re-enable the Image component of panel #3 or if I change the Image component of panel #3 to not have a source image, things work as I expect (i.e. I can click on panel #1’s button after panel #2 is SetActive(false)).

?!