Manipulating UCubeBuilder from C++

I’m trying to change the size of an UCubeBuilder inside my editor plugin. Just to try things out every time I select a brush I add +10 to the Z uproperty of its builder like so:

ABrush *brush = Cast<ABrush>(InActor);
UBrushBuilder *builder = brush->BrushBuilder;
if (builder->GetClass()->IsChildOf(UCubeBuilder::StaticClass()))
{
    UCubeBuilder *cubeBuilder = Cast<UCubeBuilder>(builder);
    cubeBuilder->Z = cubeBuilder->Z + 10;
}

The changes are reflected inside the brush settings in the details panel but the size of the builder displayed in the views and the actual brush is not changing.

This leads to my question: how to update the builder brush to reflect its new size and after finishing editing, how to update the ABrush to rebuild with it’s new builder dimensions?

I’ve not got the code in front of me at the moment, but take a look at UEditorBrushBuilder::PostEditChange for an example of how to rebuild your brush when changing properties.

I found Builder->Build(Brush->GetWorld(), Brush) inside. This did the trick. Looking into PostEditChangeProperty was a good call. The one of ABrush disclosed to me how to rebuild the actual geometry too: Brush->SetNeedRebuild(Brush->GetLevel()). Thank you sir!

Well, I think your answer is not (for 4.13 version) complete, so let me to add my two cents here: you need also to use "RebuildAlteredBSP function. Whole code would be:

ABrush *Brush;
(...)
UBrushBuilder *Builder = Brush->BrushBuilder;
UCubeBuilder *CBuilder = (UCubeBuilder *)(Builder);
CBuilder->Z += 10;

Builder->Build(Brush->GetWorld(), Brush);
Brush->SetNeedRebuild(Brush->GetLevel());
GEditor->RebuildAlteredBSP();

But thanks, your answer helped me a lot. For future seekers, I recommend a lot source file:
UnrealEngine/Engine/Source/Editor/DetailCustomizations/Private/BrushDetails.cpp ,
where are all transformations from Editor.