[How to] modify struct in details customization

NOTE: This was a question initially, but the problem was my UI displaying incorrect data. This part of the code works, so I have edited the post (and title) for anyone trying to do the same!

To set your struct, you first get a pointer to it using the IPropertyHandle that the CustomizeChildren provides.



FMyStruct* FMyStructCustomization::GetData()
{
    TArray<UObject*> objects;
    handle->GetOuterObjects(objects);

    return (FMyStruct*)handle->GetValueBaseAddress((uint8*)objects[0]);
}


Then, to change the values you get a pointer to the struct and modify it’s values. Simple as that!



handle->NotifyPreChange();

FMyStruct* data = GetData();

data->dummyFloatArray.Add(0);
data->dummyBool = true;

handle->NotifyPostChange(EPropertyChangeType::ValueSet);


2 Likes

I do it naive way:



TSharedPtr<IPropertyHandle> PropHandle;




PropHandle = StructPropertyHandle->GetChildHandle(index).ToSharedRef();

if ( ! PropHandle->IsValidHandle() ) { return; }

//...


I feel so stupid, it was working all along. The problem was my UI that was displaying incorrect data. Well, 4 hours wasted but I got it to work (finally). I won’t delete this thread because someone might be interested in knowing how to do this stuff.

Btw, [USER=“434”]BrUnO XaVIeR[/USER] I think you misunderstood the problem. What you’re doing there is getting a child handle, not the value of the struct. Thanks anyway! :slight_smile:

2 Likes

Yes… I get the child handle to modify child values.

Yeah, but as far as I know you can’t work with arrays this way. You can only set the value if it’s a primitive type, an FString, a UObject* or a few other types.