[UE5.1]Common UI How to set button hovered state when navigating with the keyboard?

I´ve written a small Subsystem to handle the Selections…

The Header file:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/Widget.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "CommonUI_HelperSubsystem.generated.h"

/**
 * A helper class to provide Widget informations to CommonUI Navigation.
 */
UCLASS(DisplayName="CommonUI_Helper")
class LOH_THETAVERN_API UCommonUI_HelperSubsystem : public UGameInstanceSubsystem
{
	GENERATED_BODY()

private:
	UPROPERTY()
	TObjectPtr<UWidget> LastSelected;
	UPROPERTY()
	TObjectPtr<UWidget> CurrentSelected;

public:
	UFUNCTION(BlueprintCallable, Category="CommonUI_Helper")
	void SelectNewWidget(UWidget* NewSelectedWidget, bool bOverrideLastSelected, UWidget*& NewCurrent, UWidget*& OldCurrent);
	UFUNCTION(BlueprintCallable, BlueprintPure=true, Category="CommonUI_Helper")
	void GetSelections(UWidget*& Last, UWidget*& Current);
	UFUNCTION(BlueprintCallable, Category="CommonUI_Helper")
	void InvalidateSelections();
};

The Cpp:

// Fill out your copyright notice in the Description page of Project Settings.


#include "CommonUI/CommonUI_HelperSubsystem.h"

void UCommonUI_HelperSubsystem::SelectNewWidget(UWidget* NewSelectedWidget, const bool bOverrideLastSelected, UWidget*& NewCurrent, UWidget*& OldCurrent)
{
	OldCurrent = CurrentSelected;
	CurrentSelected = NewSelectedWidget;
	if(bOverrideLastSelected)
	{
		LastSelected = NewSelectedWidget;
	}
	NewCurrent = CurrentSelected;
}

void UCommonUI_HelperSubsystem::GetSelections(UWidget*& Last, UWidget*& Current)
{
	Last = LastSelected;
	Current = CurrentSelected;
}

void UCommonUI_HelperSubsystem::InvalidateSelections()
{
	LastSelected = nullptr;
	CurrentSelected = nullptr;
}

And this is my code…
The interface calls are for buttons that inherit from this Common Button base…

Works now and never selects two buttons at once…

4 Likes