UMG Get Buttons references in c++

hello unreal people, i afraid i am very lost on this, i create a regular blueprint widget and design some stuff with cute buttons, now i create a custom class Bases in UUserWidget and override some functions, so i need reference all my buttons in code to iterate some things on c++ but i dont see a way to do that, is posible?

i see this:

UButton* exitButton = (UButton*)GetWidgetFromName(TEXT("exitButton"));

but find by name is not option, i need find all buttons and finally get a TArray to do my stuff work!
any suggestion?

well after some research i found this: with my anwser ja! get all widgets of class i see the source, so i rewrite to looking for just buttons, this give me back my cute buttons in a TArray without find by name
this is the trick:

UFUNCTION(BlueprintCallable, category = "Kinect", meta = (WorldContext = "WorldContextObject"))
		void getAllButtons(UObject* WorldContextObject, TArray<UButton*>& buttons);

and the cpp

void UMyWidget::getAllButtons(UObject* WorldContextObject, TArray<UButton*>& buttons)
{
	buttons.Empty();
	if (!WorldContextObject)
	{
		return;
	}

	const UWorld* world = GEngine->GetWorldFromContextObject(WorldContextObject);
	if (!world)
	{
		return;
	}
	for (TObjectIterator<UButton> Itr; Itr; ++Itr)
	{
		UButton* liveButton = *Itr;
		if (liveButton->GetWorld() != world)
		{
			continue;
		}
		buttons.Add(liveButton);
	}

}

anywhy this is not perfect!, this give back all buttons existing in the world so if you have multiple widget with his own buttons this will include in the TArray, so be careful of course you can mask to return only the buttons in the especific widget, but for now is ok for me!

greetings!!!

Thanks to ZkarmaKun for his solution. I searched a bit more on how to get only the buttons from the current user widget and to avoid looping trough every active widget.

Nick Darnell gave a helpfull hint on the forum about how it can be done so the function only returns buttons from the user widget in question:

.h

UFUNCTION(BlueprintCallable, category = "i3d", meta = (WorldContext = "WorldContextObject"))
void GetAllButtons(UObject* WorldContextObject, TArray<UButton*>& Buttons);

.cpp

void UMyUserWidget::GetAllButtons(UObject* WorldContextObject, TArray& Buttons)
{
Buttons.Empty();
if (!WorldContextObject)
{
	return;
}

const UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
if (!World)
{
	return;
}

WidgetTree->ForEachWidget([&](UWidget* Widget) {
	check(Widget);

	if (Widget->IsA(UButton::StaticClass()))
	{
		UButton* Button = Cast<UButton>(Widget);
		if (Button)
		{
			Buttons.Add(Button);
		}
	}
});



}

	
	
}