- Home /
Buttons will not change color
Hey guys so Im trying to make a Pause Menu in Unity with Buttons that change color when highlighted or pressed. Right click Canvas, UI, Button and in inspector view I change the colors for "Normal Color", "Highlighted Color" and "Pressed Color". Normal Color changes instantly but when I press play, the Highlighted and Pressed colors dont seem to work when I hover over the buttons or click them with the mouse.
Ive watched two tutorials on how to make the menu and they just quickly select the color and it works no problem. Any reason why it isnt working for some people? Using version 5.6.0f3
Do you have an EventSystem component in your scene? If this is missing, then I don't think the color transitions will work. Another point of failure is not having an image associated with your Button. Yet still could be that for some reason Color Tint isn't the type of Transition selected for the button. Finally, the alpha channel of the color might be set fully transparent. Could you post a screen grab of your Hierarchy and Inspector with the button selected?
So I do have EventSystem which automatically comes with Canvas. I Dont have any image associated with my Button but I dont think Ive ever seen anyone do that because I would use something like Sprite Swap or Animation then ins$$anonymous$$d of Color Tint that is there by default. I have the game in Play mode in the pic, youll have to take my word for it when I say the buttons dont do anything when I hover or click them.
I did another tutorial that is just making a pause button (no color affects) and adding simple code to it to pause the game. I have no error codes at all when I attach it. I press the P key, the pause menu comes up but when I press the pause button I made, nothing happens again. Its almost as if buttons are not working for me in any way, whether they have code or if im just trying to change the color! Thank you so much for replying, I really appreciate you helping me!
The only way I was able to reproduce the behavior you described is if the game window did not have focus. In development, focus is lost easily if you're making changes via the inspector. Does it still behave this way after you click back into the Game Window and then attempt mousing over or clicking the buttons?
Is there an Event Sytem on your scene, are its scripts active ? Is your button script active, is its parameter "interactable" active ?
I think so. If you look in my hierarchy, you can see EventSystem (this automatically came up when I created the canvas). How would I know if the EventSystem and Button scripts are active? Do you mean is the checkbox checked beside them? Cause it is by default. I feel like you can see all that in the image I posted.
Some of the image is over resume button and its may be text or simple panel and its raycast target is enabled and it blocking your resume button otherwise your i didn't see anything wrong in setting up hierarchy.
Answer by awaismazhar999 · Jun 15, 2017 at 11:30 AM
Dear @username
Make sure that the Transition of Button component is set to Color tint.
Make sure that Intractable property of your button property is checked.
Make sure that Event system property is present in your Hierarchy.
Did you see my image? You can obviously see all those things are present.
Answer by Hoorza · Nov 19, 2018 at 12:22 AM
The same problem occurs with 2018.2. Sucks. My quick workaround to make the 'Normal' color to come back after the button has been released:
In my function that is called when the button is depressed, I disable and then right after I enable 'Button' component.
exampleButton.enabled = false;
exampleButton.enabled = true;
Not visible to the viewer and it brings the normal color back. I know it is not the right way but it is quick and easy fix. So far I have not had any issues with this approach.
P.S. I use 'Event Trigger (Script)' and 'PointerUp' Event Type to call some functions when the button is being released. That is where I have put my reset code.
Answer by StarKen · Jan 19, 2020 at 05:33 AM
ok. just found out that my image color should be transparent like 140 and button color to your preferences.
easy to get confused when you set your image color to black.
Answer by wspnut · Mar 06, 2018 at 08:05 PM
I'm having the same problem - my settings are as listed, too. Did you ever find a resolution?,I'm having the same problem; all of my settings are checked as well - very odd.
To answer my own question (of course I figure this out right after I post - rubber duck debugging at work), in case anyone else needs help:
I had removed the default Inputs from the Project Settings. I was getting an Error until I re-added the Submit
and Cancel
Input options (unused). Once that was fixed, the highlighting worked as expected.
I personally don't see the rationale behind it, and it feels like a bug or oversight in the implementation of the EventSystem.
Answer by breaddy · Mar 28, 2018 at 03:21 AM
I had the same problem and debugged it somehow lol. The reason my button is not being highlighted is that I have an image with a transparent background that is covering my button's ray case. So I go to my image and disable the "Raycast Target" option. :) Fixed
Your answer
Follow this Question
Related Questions
Pause menu not working 1 Answer
Game stays paused after Restart. 1 Answer
Pause Game Through Button UI Click Instead of Escape Key? 2 Answers
PS4 MENU not functioning 0 Answers