I created a custom button and lost the ability for unity to have navigation between custom buttons

I created a custom button so that the right click is differentiated from the left

public class CustomButton : Selectable
    {
        [SerializeField]
        private Button.ButtonClickedEvent m_OnLeftClick = new Button.ButtonClickedEvent();
        [SerializeField]
        private Button.ButtonClickedEvent m_OnRightClick = new Button.ButtonClickedEvent();

        public Button.ButtonClickedEvent onLeftClick
        {
            get
            {
                return this.m_OnLeftClick;
            }
            set
            {
                this.m_OnLeftClick = value;
            }
        }

        public Button.ButtonClickedEvent onRightClick
        {
            get
            {
                return this.m_OnRightClick;
            }
            set
            {
                this.m_OnRightClick = value;
            }
        }

I add these buttons in a menu with a GridLayoutGroup.

When I try to navigate using keyboard I can’t do it

As seen in the image, navigation is activated and is recognized by unity. If I try to add classic buttons to this same GridLayoutGroup. These do allow me to navigate

I saw in the Button code in unity add these interfaces IPointerClickHandler, ISubmitHandler, IEventSystemHandler, try to do the test so that it is public class CustomButton : Selectable,IPointerClickHandler, ISubmitHandler, IEventSystemHandler but it still does not navigate.

With the mouse everything works perfectly.

I believe that stuff is controlled by the EventSystem, so Unity doesn’t know what the Selected GameObject is until you tell it what it is, as they’re custom buttons. Have you tried using EventSystem.SetSelectedGameObject?

Navigation in a Selectable is controlled here:

Also I don’t see a really compelling reason to have created a custom class here. Why not just throw these two components on your object:
Selectable
EventTrigger

Thanks for your reply

Navigation is automatic.

8777464--1191535--Screenshot 2023-02-02 174831.png

I did another test overriding the highlighted, pressed and selected colors. But it never turns to the selected color. I think the problem must be linked.

If I add the Selectable component and Event Trigger, I lose the ability to tell right click from left click. Although the navigation returns

I personally wouldn’t extend Unity’s own component types.

Make a it a separate component that simply hooks into the existing Unity component.

No you don’t

The PointerEventData object you receive as a parameter in the callbacks for OnPointerClick etc give you that information:
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.PointerEventData.html#UnityEngine_EventSystems_PointerEventData_button
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.PointerEventData.InputButton.html

Got it, thank you