So I have a custom UGameInstance
called gameInstance
.
I also have a BlueprintCallable
method where I can set my custom C++ list of objects that looks like following:
void AMyActor::SetLists(UListView* l)
{
auto callback = [this, l](MyObjectList* list)
{
for (auto& item : list->GetItems())
{
gameInstance->GetList(&item);
FString name = item.GetName();
UMyExtendedWidget* row = NewObject<UMyExtendedWidget>();
row->AddText(name);
// set other data here
l->AddItem(row);
}
};
gameInstance->GetLists(callback);
}
And I have my UMyExtendedWidget
which is a widget I had to extend because I have multiple components in a single row (two buttons, image, and a text, in the blueprint designer they are all under horizontal box component), and it looks like following:
UCLASS(BlueprintType, Blueprintable)
class QUICKSTART_API UMyExtendedWidget : public UUserWidget
{
GENERATED_BODY()
public:
UMyExtendedWidget(const FObjectInitializer& ObjectInitializer);
void AddText(FString name)
void AddButtonOne(FString url);
void AddButtonTwo(FString url);
void AddImage(FString url);
public:
virtual void NativeConstruct() override;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UButton* MyButtonOne;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UButton* MyButtonTwo;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UImage* MyImage;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* MyLabel;
};
Which I all placed under HorizontalBox in the UI of UMyExtendedWidget in the blueprint.
However, UMyExtendedWidget::NativeConstruct
gets called one or more frames after call to AMyActor::SetLists
and the data I set through AMyActor::SetLists
never get to be rendered.
Is there a way to avoid this? What are my options?