• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by OblicaStudio · Jun 07, 2021 at 11:46 AM · uibuttonpanelpopup

Button on Panel is not responding

I have a Panel added into a Canvas. I am using this Panel as showing popup/dialog to user. In the design mode this Panel is not position into the game view and kept aside (away from Camera viewport). When I need to show this Panel I position it in the center of the screen using following script:

GameObject popup = GameObject.Find("Popup"); popup.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2, Camera.main.nearClipPlane));

It does shows in the middle of screen but Button placed on this Panel is non clickable or does not respond to click. I have attached debugger to this button OnClick method and it does not hit.

When I keep this panel all the time in game view, this button is clickable and execute OnClick method.

Canvas's Render Mode is set to "Screen Space - Camera"alt text

Please refer the attached image for more detail.

issue.png (33.1 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Earthshine · Jun 07, 2021 at 12:24 PM 0
Share

Is there anything in popup children that could block the raycast to the button? Can you please make a screenshot with the popup gameobject expanded?

avatar image DevManuel · Jun 07, 2021 at 02:26 PM 0
Share

Have you already tried another method to activate the popup? Maybe try this:

 public GameObject popup; // store object to avoid any issue
 
 
 public void setPopup(bool set){  //button trigger 
    popup.SetActive(set);
 }
 
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by OblicaStudio · Jun 08, 2021 at 10:34 AM

@Earthshine, I dont think so. I have added screen shots of Popup structure. This screen shot also contains Inspector values of Popup Panel and Button. alt text

I my understanding, I have put Popup Panel out of Canvas rendering area at design time (Scene View) but I am pulling Popup Panel inside Canvas via changing its position to middle of screen and that may causing the issue. My Canvas's Render Mode is set to "Screen Space - Camera" so at design time it is covering Main Camera view port, its not like the huge default Canvas size I have here.


issue-2.png (82.4 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Earthshine · Jun 08, 2021 at 11:33 AM 0
Share

Everything looks ok in your screenshots as far as I can see.

I actually don't know if popup.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2, Camera.main.nearClipPlane)); should give you the right position on the Canvas and I don't know if button can be clicked if its outside the canvas plane. AFAIK you are supposed to use RectTransform for moving and placing objects in the UI.

I wouldn't even take this route however, because I see no reason for moving the popup. I would instead write a script that disables the popup when the game starts and enables it again when the level ends, so I may leave it disabled or enabled in the edit mode.

avatar image OblicaStudio · Jun 08, 2021 at 11:56 AM 0
Share

Bingo!!!. Thanks a lot for pointing me into right direction. For UI objects, changing transform.position does not work. So as mentioned by you, I have used RectTransform and it worked.

popup.GetComponent().anchoredPosition = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width / 2, Screen.height / 2));

I understand this may not be the right approach (keeping panel outside Canvas at design time and bring it back on Canvas at runtime) but it greatly declutter my objects space at design time.

Thanks again!!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

223 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why are my UI elements hidden behind the background? 3 Answers

Button onClick events will not be triggered 1 Answer

What is the code to load a panel that is not a buildIndex scene? 1 Answer

In game right click menu 1 Answer

How to play two animations with one UI button? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges