I’m having trouble with the following C++ code in UE 5.1.
I make a UserWidget derived class and create a Blueprint instance of it, say to hold a label and a SpinBox for a value. (I’m making an in-game Details panel to display properties for objects)
UCLASS()
class MYPROJECT_API UFloatValue : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
class UTextBlock* Label;
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
class USpinBox* SpinBox;
};
I then set up another UserWidget derived class that will have a template of one of these that it clones repeatedly, to fill out a list based on some backend data
UCLASS()
class MYPROJECT_API UEditorDialog : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
class UVerticalBox* Container;
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
class UFloatValue* FloatValueTemplate;
UFUNCTION(BlueprintCallable)
void Fill(TArray<FString> labels, TArray<float> values);
};
The Fill function takes a array of strings and an array of floats and clones the template for each one, and places it in the container.
void UEditorDialog::Fill(TArray labels, TArray values)
{
for (int i = 0; i < labels.Num() && i < values.Num(); i++)
{
UFloatValue* ed = DuplicateObject(FloatValueTemplate, Container);
ed->Label->SetText(FText::FromString(labels[i]));
ed->SpinBox->SetValue(values[i]);
Container->AddChild(ed);
}
FloatValueTemplate->SetVisibility(ESlateVisibility::Hidden);
}
This all worked in Unreal 5.0, and would display the names and values that I’d passed into the Fill function.
In Unreal 5.1, this seems to be broken. The labels and values for each duplicated object appear as the default, even though I can see it stepping through the loop in Fill() and calling SetText and SetValue on valid pointers.
My main project is more complex, this is a very simple example I put together in 5.0, where it works correctly. Migrating it to 5.1 breaks it.
Has anyone else experienced this?
And, I’m new ish to Unreal. Does this seem like a reasonable way to go about creating a data-driven UI?
(I submitted a bug a couple of weeks ago with an example project on Git, but havent heard back)