Setting the value of an Instance of UProperty

Hi all!

I’m trying to set the value of a UProperty on a UMG Spinbox, then when the SpinBox value changes, set that value back on the Property. For that, I’m doing the next:

I iterate through all properties of an object with a specific Meta, then build another Widget (the widget that has the SpinBox) depending on the type that contains its Meta and finally pass the UProperty to the created new Item:

// Get properties of the owner and its components
  TArray<UProperty*> PropertiesToShow;
  static FMargin Padding(100);
  for (TFieldIterator<UProperty> It(OwnerActor->GetClass()); It; ++It)
  {
    if (It->HasMetaData("ModifiableProperty"))
    {
      UPropertyEditorItem* Item = nullptr;
      switch (It->GetINTMetaData("ModifiableProperty"))
      {
        case 0:
          Item = NewObject<UPropertyEditorItem>(this, PropertyWidgetClassFloat);
        break;
        case 1:
          Item = NewObject<UPropertyEditorItem>(this, PropertyWidgetClassInt);
        break;
        case 2:
          Item = NewObject<UPropertyEditorItem>(this, PropertyWidgetClassBool);
        break;
      }
      // Fill Item and add to Hierarchy
      if (Item)
      {
        ScrollBox->AddChild(Item);
        Item->SetupItem(OwnerActor, *It);
        Item->SetPadding(Padding);
      }
    }
  }

Until here everything is working fine as expected, getting the values of the UProperty works well, but then when I try to modify the value of any of the above properties, It doesn’t change. I’ve read in many other answers that UProperty contains the value and information of the Property but it isn’t the instance of it, so when changing it, nothing happens.

This is how I’m doing it:

void UPropertyEditorItemFloat::SetupItem(APickupableActor* PickupObj, UProperty* Property)
{
  Super::SetupItem(PickupObj, Property);
  ValuePtr = Cast<UFloatProperty>(Property);
  if (ValuePtr)
  {
    PropertySpinBox->SetValue(*ValuePtr->ContainerPtrToValuePtr<float>(PickupObj));
    ValueChanged.BindUFunction(this, "UpdateValue");
    PropertySpinBox->OnValueChanged.Add(ValueChanged);
  }
}

void UPropertyEditorItemFloat::UpdateValue()
{
  ValuePtr->SetPropertyValue(PickupProperty, PropertySpinBox->GetValue());
}

void UPropertyEditorItemFloat::SyncValue()
{
  PropertySpinBox->SetValue(*ValuePtr->ContainerPtrToValuePtr<float>(PickupProperty));
}

I’m really upset because I’ve been like a week researching in the API and Forums, trying so many things but nothing worked out.

I hope you can help me, thanks in advance!

Maybe try this function instead:

You can find API reference here, check parent classes too:

https://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/UFloatProperty/index.html

Also do set function is actually called? make sure by placing breakpoint on it

Thanks, Shadow!

Works like a charm!

I’m leaving the call of the function below if anyone is wondering how to do it:

void UPropertyEditorItemFloat::UpdateValue()
{
  ValuePtr->SetFloatingPointPropertyValue(PickupProperty->ContainerPtrToValuePtr<float>(PickupPropertyOwner), PropertySpinBox->GetValue());
}