Setting colour in c++ might help anyone trying to do that

Might help someone, I approached it differently and set the color in C++ (and was extremely lazy and just set everything back to white before setting the new selected color, I wouldn’t do that for real (honest!) I’d add a currently selected index etc.)

Setting the color was way harder than I expected you have to include the two obvious includes

#include "Styling/SlateColor.h"
#include "Math/Color.h"

But it still wont compile, turns out slate color is in a different module called SLATECORE so you have to add that into the PuzzlePlatforms.Build.cs file as well like we did for the onlinesubsystem etc.

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "UMG" , "OnlineSubsystem" , "SLATECORE", "OnlineSubsystemSteam" });

I found a handy way to check if something needs an additional module, if you search for it and look at the strcut piece you can get a hint there for what might be needed then search to confirm etc.

struct SLATECORE_API FSlateColor

My very lazy code, I wanted to practice iterating through objects in a for loop and casting them so did it like this, there are better ways to do it but it was fun to figure out. I added a function to get a reference to the actual text block but looking at how SetColorAndOpacity works I think I probably could have just applied it at parent level and it would have cascaded down to child elements, but I wanted to practice getting references anyway.

void UMainMenu::SelectIndex(uint32 Index)
{
	SelectedIndex = Index;

	//ServerList->GetChildAt(Index)->SetToolTipText(FText::FromString("asdasdasdasdasd"));

	//UEditableText* t = Cast<UEditableText>(ServerList->GetChildAt(Index));

	UServerRow* r;
	
	TArray<UWidget*> AllChildren = ServerList->GetAllChildren();

	for (UWidget* Child : AllChildren)
	{
		r = Cast<UServerRow>(Child);
		if (IsValid(r))
		{
			UTextBlock* t = r->GetTextBlock();

			if (IsValid(t))
			{
				t->SetColorAndOpacity(FSlateColor(FLinearColor(1, 1, 1, 1)));
			}

		}
	}

	
	r = Cast<UServerRow>(ServerList->GetChildAt(Index));

	if (IsValid(r))
	{
		UTextBlock* t = r->GetTextBlock();

		if (IsValid(t))
		{
			t->SetColorAndOpacity(FSlateColor(FLinearColor(1, 0.5f, 0.5f, 1)));
		}

	}

	UE_LOG(LogTemp, Warning, TEXT("Selected Index callback %d"), SelectedIndex.GetValue());
}

Privacy & Terms