Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by SuperManitu · Feb 28, 2015 at 04:22 PM · uibutton

[Solved] (4.6 UI) Button is highlighted without mouse hovering

Hi, I've made a basic pausemenu with the new UI system. But when I open and close a submenu the button clicking doesn't work well any more. I made a gif (yellow=highlighted, red=pressed): alt text

I haven't much code to show, because I mainly used the editor and if I don't use the mouse but a gamepad (which is handled by my code) everything works well. It seems to be a problem with the graphical raycaster or something like this. Any Ideas?

Comment
Add comment · Show 10
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 Mmmpies · Feb 28, 2015 at 04:48 PM 0
Share

That image link is broken, can you fix it?

avatar image SuperManitu · Feb 28, 2015 at 05:09 PM 0
Share

should be fixed now

avatar image Mmmpies · Feb 28, 2015 at 05:13 PM 0
Share

Start the game with $$anonymous$$aximizeOnPlay NOT selected. Highlight those Buttons in the Panel and have it so you can see the scene view and the game view. See if you can spot at what point the rect transform is moving or at least see if we can get some more info.

avatar image SuperManitu · Feb 28, 2015 at 05:37 PM 0
Share

the rect transform isn't moving and there are no (visible) changes to the buttons. But I recocnized that when you click (right click, because it isn't used for activating something) the highlighting is normal again. Should I try to make a dirty workarount and make a rightclick event after the transition?

avatar image SuperManitu · Feb 28, 2015 at 05:48 PM 0
Share

Here is the GIF:

alt text

Show more comments

1 Reply

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

Answer by Mmmpies · Mar 01, 2015 at 11:14 AM

Got it, the problem is the canvas accepts buttons from both objects because you want to see both on screen at the same time we have to do something different from normal, normally you'd normally SetActive to false on the canvas you don't want to interact.

So Add A Canvas Group on both the Main and Settings base object:

MainSettings

Set the main so interactable and blocksRaycast are ticked and do the opposite for the settings CanvasGroup:

CanvasGroup

Now edit your scripts, first Settings:

 using System;
 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections.Generic;
 
 public class Settings : Button
 {
     public CanvasGroup SettingsCG;
     public CanvasGroup MainCG;
 
     protected override void OnActivated()
     {
         submenuManager.OpenSubmenu(1);
         MainCG.blocksRaycasts = false;
         MainCG.interactable = false;
         SettingsCG.blocksRaycasts = true;
         SettingsCG.interactable = true;
     }
 }

Then Back:

 using System;
 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections.Generic;
 
 public class Back : Button
 {
     public CanvasGroup MainCG;
     public CanvasGroup SettingsCG;
 
     protected override void OnActivated()
     {
         submenuManager.CloseSubmenu(1);
         MainCG.blocksRaycasts = true;
         MainCG.interactable = true;
         SettingsCG.blocksRaycasts = false;
         SettingsCG.interactable = false;
     }
 }

Drag the Objects with the CanvasGroup onto the relevant slot in your field area.

Should solve the problem.


mainsettings.png (5.5 kB)
canvasgroup.png (6.0 kB)
Comment
Add comment · Show 6 · 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 SuperManitu · Mar 01, 2015 at 11:29 AM 0
Share

thanks, it worked

EDIT: Now it doesn't seem to work :o When I go back, the first button is selected permanently, when I hover over the second, both are highlighted.

avatar image Mmmpies · Mar 01, 2015 at 12:32 PM 0
Share

Technically the original problem is solved. This is an additional issue. Looking at now though.

EDIT

That's a complex structure you got there, I think it's holding the value of the previous button clicked somewhere. If you press Esc -> Continue -> Esc -> Settings it Exits as though Continue has been clicked, same for the other way round if you click on Settings and then back it appears to hold the value.

Totally separate issue to the one posted and something in your code holding the last clicked button.

Why not simplify it and use the EventTrigger to display the animation/color change, use onClick to call the function ins$$anonymous$$d of extending the Button function?

EDIT 2

Also I just went back to your original scene without my fix in it and the other issues are there just not a obvious as as the question you asked originally.

EDIT 3

I've been thinking about this and I think the issue is you're extending the button class. If you click the Settings button there's absolutely no way it can do anything other than call the associated script, but because you extend the Button it's possible your code is reacting to the OnClick elsewhere. That's the only way it can happen. I know it's horrible but I think you need to rewrite so you just access public functions to handle clicks and not directly access the OnClick.

avatar image SuperManitu · Mar 01, 2015 at 04:56 PM 0
Share

I don't derive from the button class, but from my button component (same class name, different namespace), which has an abstract function onClick and I use it for a clean OOP design. Here is a new zip if you need. And it's not held in my code, because it works without a mouse.

avatar image Mmmpies · Mar 01, 2015 at 05:22 PM 0
Share

I reverted back to your original upload before my script/CanvasGroup got anywhere near that scene. The issues you mention after my fix got applied to it were already there. You press Esc -> Continue -> Esc -> Settings it exits the menu as though Continue had been clicked. That happens in the original upload and in the one you just uploaded. It's got nothing to do with the CanvasPanel Fix I showed you.

Fundamentally your scripts are calling one buttons actions even though a different button is being pressed. Honestly that's a mess, an impressive mess but a mess all the same.

Really don't name a class the same as a Component that way you can avoid confusion but there are far easier ways of doing this. The event system already handles clicks and is robust and very, very good. Is there a reason for the complexity?

Currently the only part that's working as expected is the CanvasGroup fix.

EDIT

Well there's shouldn't and and what's actually happening, try what I suggested Esc -> Continue -> Esc -> Settings if it exits the menu then Settings is being clicked and Continue is being called, that's what's actually happening.

avatar image SuperManitu · Mar 01, 2015 at 05:27 PM 0
Share

$$anonymous$$y buttons aren't calling other buttons than pressed (not intended at least). O$$anonymous$$, the name could be different, but that shouldn't produce this bug. I did that system for an easy gamepad integration.

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to create a button for every supported resolution? 1 Answer

Can't get 4.6 GUI Button to Load Scene (Solved) 1 Answer

Button is being triggered by spacebar after clicked once 1 Answer

Launching an animation with new GUI in Unity 4.6 1 Answer

(4.6 UI) Button is highlighted permanently 3 Answers


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