Items in Tile View not showing correct data.

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.

Upon looking further, I realized I was using the TileView incorrectly. If anyone else runs into this problem, you must pass UObjects into the TileView using AddItem. Creating a widget does absolutely nothing. You also must use NativeOnListItemObjectSet as OnListItemObjectSet is only available for BP. Once you use Native, you will be good to go.

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