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.