I have a market actor that on begin play sets the market asset data. void
AMarketActor::SetupMarket()
{
AFPSPlayerController* PC = Cast<AFPSPlayerController>(GetWorld()->GetFirstPlayerController());
if (PC)
{
PC->UpdateMarket(MarketDataAsset);
}
}
// Called when the game starts or when spawned
void AMarketActor::BeginPlay()
{
Super::BeginPlay();
SetupMarket();
}Which calls void AFPSPlayerController::UpdateMarket(UMarketDataAsset* CurrentMarket)
{
if (MarketWidget)
{
MarketWidget->SetMarketDataAsset(CurrentMarket);
MarketWidget->SetupWidget();
}
}
Which then calls
void UMarketWidget::SetupWidget()
{
UE_LOG(LogTemp, Warning, TEXT("SetupWidget called."));
if (MarketDataAsset)
{
for (FMarketItemData& item : MarketDataAsset->MarketItems)
{
// Create the widget and add to list.
UMarketItemWidget* ItemWidget = CreateWidget<UMarketItemWidget>(GetWorld(), UMarketItemWidget::StaticClass());
ItemWidget->SetItemData(item);
TileView->AddItem(ItemWidget);
}
}
}
and so this is my marketItemWidget, this is an item of the tileview. Im using a tilewidget
void UMarketItemWidget::SetItemData(const FMarketItemData& NewData)
{
UE_LOG(LogTemp, Warning, TEXT("MarketItemWidgetAddress address: %p"), this);
UE_LOG(LogTemp, Warning, TEXT("NewData address: %p"), &NewData);
UE_LOG(LogTemp, Warning, TEXT("ItemData address before assignment: %p"), &ItemData);
ItemData = NewData;
UE_LOG(LogTemp, Warning, TEXT("ItemData address after assignment: %p"), &ItemData);
UE_LOG(LogTemp, Warning, TEXT("ItemName after SetItemData: %s"), *ItemData.ItemName);
}
void UMarketItemWidget::SynchronizeProperties()
{
Super::SynchronizeProperties();
// Log to check if method is called
UE_LOG(LogTemp, Warning, TEXT("UMarketItemWidget::SynchronizeProperties - Method called"));
if (ItemNameTextBlock)
{
ItemNameTextBlock->SetText(FText::FromString(ItemData.ItemName));
// Log to verify the data is set to ItemNameTextBlock
UE_LOG(LogTemp, Warning, TEXT("UMarketItemWidget::SynchronizeProperties - Data set: %s"), *ItemData.ItemName);
}
else
{
// Log if ItemNameTextBlock is null
UE_LOG(LogTemp, Warning, TEXT("UMarketItemWidget::SynchronizeProperties - ItemNameTextBlock is null"));
}
}
But when opening my widget, the itemmarkettextblock is empty. Why? Looking at the debugger it gets set correctly but upon opening my widget, poof the data is gone. It seems like its creating a new widget. I’m not too sure.