I’ve create this custom IDetailCustomization:
Header:
class FCbeTestDetailsPanel : public IDetailCustomization
{
public: static TSharedRef<IDetailCustomization> MakeInstance();
virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override;
FReply OnButton();
private:
TArray<TWeakObjectPtr<UObject>> m_selectedComponents;
};
Cpp:
TSharedRef<IDetailCustomization> FCbeTestDetailsPanel::MakeInstance()
{ return MakeShareable(new FCbeTestDetailsPanel);
}
void FCbeTestDetailsPanel::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{ DetailBuilder.GetObjectsBeingCustomized(m_selectedComponents);
IDetailCategoryBuilder& CustomCategory = DetailBuilder.EditCategory("Test Category");
FText Caption = FText::FromString("Test Button");
CustomCategory.AddCustomRow(Caption)
[INDENT=2].ValueContent()
[/INDENT]
[INDENT=3]SNew(SButton)
.Text(Caption)
.OnClicked(this, &FCbeTestDetailsPanel::OnButton)[/INDENT]
[INDENT=2]];[/INDENT]
}
FReply FCbeTestDetailsPanel::OnButton()
{ for (auto selectedObj : m_selectedComponents)
{
[INDENT=2]UBoxComponent* pBoxComponent = Cast<UBoxComponent>(selectedObj.Get());
if (IsValid(pBoxComponent))
{[/INDENT]
[INDENT=3]pBoxComponent->SetRelativeLocation(FVector::OneVector * FMath::FRandRange(50, 100));
pBoxComponent->Modify();[/INDENT]
[INDENT=2]}[/INDENT]
}
return FReply::Handled();
}
I register it in my editor module:
FPropertyEditorModule& propertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
propertyModule.RegisterCustomClassLayout(UBoxComponent::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&FCbeTestDetailsPanel::MakeInstance));
Now, what happens is: when I add a BoxComponent to Actor in a blueprint my TestButton is visible. I can move this BoxComponent around viewport, everything is fine. Then I press my TestButton, BoxComponent’s location is set to some random value, as it should be, but it isn’t updated on viewport and I can’t move this component on viewport anymore. Manually setting location value in details panel also doesn’t work anymore.
Closing blueprint tab and opening it again fixes this problem - viewport and details panel are synchronized again. But when I press my TestButton this problem appears again.
Help?