x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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"

Custom Widget consisting of a text and an icon

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.

Script

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

alt text

I would like to understand why.

Thank you !

Product Version: UE 4.20
Tags:
more ▼

asked Feb 03 '19 at 10:54 AM in Blueprint Scripting

avatar image

x115
1 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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 :

Modified Script

And the final result :

Result

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

more ▼

answered Feb 04 '19 at 05:22 AM

avatar image

x115
1 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question