Async Loading Assets from DT to Brushes only last asset is shown

Hello everyone,

I have some difficulties to understand what is happening here. I have a custom widget called “TextIcon”

This widget is meant to be put in a scroll box. I gather the informations needed to construct this widget from a datatable and then add it as a child to the scrollbox. Here is the script that I have made.

However, this script partially works. Because as you can see below, only the last icon is shown.

I would like to understand why.

Thank you !

I have changed my manner of doing this, I’ve moved the loading process into c++. It is still a little messy but at least it works. I post my solution here, it may help other people.

I have created a class which derives from UUserWidget.

// Pre-declaration
class UImage;
class UTextBlock;
class UDataTable;

/**
 * 
 */
UCLASS()
class MYPROJECT3_API UImageWidget : public UUserWidget
{
	GENERATED_BODY()

public:
	// This function assumes that the datatable is based on FSubjectDataTableRow structure
	UFUNCTION(BlueprintCallable, Category = "Custom")
	void ConstructFromDataTable(UDataTable * DataTable, FName RowName);

private:
	// The icon
	UPROPERTY(meta = (BindWidget))
	UImage * Icon;

	// The label
	UPROPERTY(meta = (BindWidget))
	UTextBlock * Label;
};

The meta tag “BindWidget” permits to access certain parts of the widget, the names must correspond with the names in the UMG widget.

The data table is created upon a structure that I’ve made in C++. I put it here as well.

#include "CoreMinimal.h"
#include "Engine/DataTable.h"
#include "Engine/Texture.h"
#include "SubjectDataTableRow.generated.h"

/**
 * 
 */
USTRUCT(BlueprintType)
struct FSubjectDataTableRow : public FTableRowBase
{
	GENERATED_BODY()
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FText Label;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TSoftObjectPtr<UTexture> Icon;
};

The source file :

#include "ImageWidget.h"
#include "SubjectDataTableRow.h"
#include "UMG/Public/Components/Image.h"
#include "UMG/Public/Components/TextBlock.h"
#include "Engine/DataTable.h"

void UImageWidget::ConstructFromDataTable(UDataTable * DataTable, FName RowName)
{
	if (DataTable != nullptr)
	{
		FSubjectDataTableRow * Data = DataTable->FindRow<FSubjectDataTableRow>(RowName, "", false);

		if (Data != nullptr)
		{
			Label->SetText(Data->Label);
			
			// Test if the pointer points to something
			if (Data->Icon.IsNull() == false)
			{
				Icon->SetBrushFromTexture(Cast<UTexture2D>(Data->Icon.LoadSynchronous()));
			}
		}
	}
}

Here is the modified blueprint script :

And the final result :

If someone has any advice or criticism let me know, as it would make me progress.

Hello, thanks for your answer. Your method pushed me to the idea to try async load texture in bp. So I check and its possible, for 4.22 at least.

Define our struct for texture icon in code :

...
	/* Weapon Icon reference */
	UPROPERTY(EditAnywhere, BlueprintReadOnly)
		TSoftObjectPtr<UTexture2D> WeaponIconRef;
...

And in widget on preconstruct event just call AsyncLoadAsset, and cast to Texture2d. And all textures will be loaded.

Hope this would be helpful.