Calling UUserWidget buttons from integer input

I have two UUserWidget with corresponding blueprint widgets.
UConstructionWidget, UTabJobWidget, WBP_ConstructionWidget and WBP_TabJobWidget.
The WBP_ConstructionWidget have three buttons (WBP_TabJobWidget). I’m Trying to add them to an TArray so I can cycle though them with GamePad inputs. But every time I call the array, it crashes. Even when I call to see if the array is nullptr.

header:

UCLASS()
class MYGAME_API UConstructionWidget : public UUserWidget
{
	GENERATED_BODY()
protected:
	UPROPERTY(VisibleAnywhere, meta = (BindWidget), Category = "Construction Widget | Construction Data")
	UTabJobWidget* Tab1;

	UPROPERTY(VisibleAnywhere, meta = (BindWidget), Category = "Construction Widget | Construction Data")
	UTabJobWidget* Tab2;

	UPROPERTY(VisibleAnywhere, meta = (BindWidget), Category = "Construction Widget | Construction Data")
	UTabJobWidget* Tab3;

	TArray<UTabJobWidget*> TabArray;

cpp:

void UConstructionWidget::NativeConstruct()
{
	Super::NativeConstruct();
	TabArray.Add(Tab1);
	TabArray.Add(Tab2);
	TabArray.Add(Tab3);
}
//...
void UConstructionWidget::UpdateTab(const int8 TabIndex)
{
	TabArray[TabIndex]->ToggleTab(); // This causes a crash
}

Is it something wrong with my array? Or can’t I reference the buttons like this?

Tab1->ToggleTab(); // this also causes a crash

PS: the widget works in the sense that I can open the menu, see the three buttons, highlight them by hovering the mouse, click each button for an UE_LOG message, change the color from within cpp. But It crashes when I call the UpdateTab() function containing TabArray.

Just wanted to say that I solved it, but I went into SCompoundWidget class and used slate instead. For those that are searching for the answer of how to change tab with input from HUD. In your SCompoundWidget header:

//...
	void UpdateTab(int32 InputTabIndex);

private:

	int32 TabIndex;
	//Getter
	int32 GetCurrentTabIndex() const { return TabIndex; }
//...

in your SCompoundWidget cpp:

//...
	SNew(SWidgetSwitcher) //Tab1
	.WidgetIndex(this, &SMyCompoundWidget::GetCurrentTabIndex)
	+SWidgetSwitcher::Slot()
	[
	//...
	]
	+ SWidgetSwitcher::Slot() //Tab2
	[
	//...
	]
	+ SWidgetSwitcher::Slot() //Tab3
	[
	//...
	]
//...
}

void SMyCompoundWidget::UpdateTab(const int32 InputTabIndex)
{
	TabIndex = InputTabIndex;
}

The function UpdateTab is called from MyHud with the int32 using value 0,1,2. I used this tutorial as guidance

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.