[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?

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:

41597-mainsettings.png

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

41598-canvasgroup.png

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.