Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by KrisM · Aug 18, 2016 at 02:57 AM · scripting problemcanvasbuttonscursor

Problems with UI buttons and Cursor position (or) UI buttons and instantiated canvas.

I've got a bit of a unique problem, and am having trouble understanding the cause.. let alone the solution.

I'm instantiating a canvas that is hidden until a player accesses their character stats. When they push 'i', the canvas becomes visible, and the cursor unlocks and becomes visible. However, buttons in this canvas do not work.

I'm using the FirstPersonControler that comes with Unity. Cursor visible/lock state is handled by this code:

         if (Input.GetButtonDown("Inventory"))
         {
             lookCursor = !lookCursor;
         }
 
         if (lookCursor == true)
         {
             firstPersonController.enabled = false;
             Cursor.lockState = CursorLockMode.None;
             Cursor.visible = true;
 
             PlayerStats playerStatsscript = gameObject.GetComponent<PlayerStats>();
             playerStatsscript.statsPanelOpen = true;
         }
         if (lookCursor == false)
         {
             firstPersonController.enabled = true;
             Cursor.visible = false;
 
             PlayerStats playerStatsscript = gameObject.GetComponent<PlayerStats>();
             playerStatsscript.statsPanelOpen = false; 
         }


The statsPanelOpen simply alternates the Canvas SetActive bool.

If I run the game with the canvas already in the scene, the button works (the EventSystem is also preloaded in either case). However, if I instantiate the Canvas, and make the cursor visible and unlocked via the above code, buttons in the instantiated canvas and buttons that are in pre-existing canvases do not work. This leads me to believe that the cursor position isn't being recognised by the EventSystem.

Instantiating the EventSystem after the Canvas does not help either.

Adding onClick Listeners and Delegates do not register either.

Any help is greatly appreciated.

Cheers,

Kris.

Edit: I've just tried removing the Cursor visible/locked codes, and used 'esc' to get a cursor visible with the Canvas open. Buttons did not work on the instantiated Canvas, but do on the pre-existing Canvas.

Comment
Add comment
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

1 Reply

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

Answer by KrisM · Aug 18, 2016 at 06:32 AM

Sometimes, you spend days trying to figure out a problem... looking in all the wrong places. Or 'right places' for people that actually have problems. Me.. I'm just a victim of 'idiot UI layout'.

It's not surprising that no one responded to the above. The details to solve the issue weren't available.

For anyone having similar problems... make sure you don't have any UI components that are in front of your buttons. They tend to prevent the EventSystem from registering button clicks.

For me, I have an entire screen UI panel that flashed red when the character received damage. This was conveniently placed in front of all my buttons. A simple index move, and it all works.

For those that need to move indexes within C#, here's the script I used (where '1' is the number of positions it moved up):

         damageFlashIndex = instantiatedPlayerDamageFlash.transform.GetSiblingIndex();
         instantiatedPlayerDamageFlash.transform.SetSiblingIndex(damageFlashIndex - 1);

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

81 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

Related Questions

AddListener fuction throwing a NullReferenceException error 1 Answer

UI Appear not appearing after build 0 Answers

UI Button not accurate 1 Answer

Mouse Cursor Problem 0 Answers

Possible for 10 canvas in 1 scene? 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