How to reset to default a property of an actor in C++

Hello,

In the world, we have hundreds of instances of a blueprint actor placed. I would like to reset to default one property of all those instances. Just changing the value back to the default value is not enough because I need each instance to use the value specified in the blueprint.

I’m trying to find a way to do that in C++ with no success.

From a world, i’m getting all the concerned actors and i would like to call something like

void SDetailSingleItemRow::OnResetToDefaultClicked() conston a specific property.

Thank you.

Hi, Pierre-Marc Berube,

Unfortunately, mimicking the behavior of most features found in the Details Panel and other Property Editors is usually not trivial. However, there is a quick-and-dirty shortcut you can use. You can basically “borrow” a lot of functionality from the Property Editor Module by creating a temporary “Single Property View” observing the property you are interested in. This does internally create temporary Slate Widgets just to throw them away, but it exposes a powerful API based on IPropertyHandle. Property Handles refer to nodes in a property tree that contains all the necessary information to handle the many property operations supported by Property Editor UIs. Here’s some code I just tested successfully:

`#include “MyEditorLibrary.h”

include “Modules/ModuleManager.h”
include “PropertyEditorModule.h”
include “ISinglePropertyView.h”
include “PropertyHandle.h”

void UMyEditorLibrary::ResetPropertyToDefault(TArray<AActor*> InActors, FName InPropertyName)
{
FPropertyEditorModule& PropertyEditorModule = FModuleManager::GetModuleChecked(“PropertyEditor”);

for (AActor* Actor : InActors)
{
// Get property handle
TSharedPtr SinglePropertyView = PropertyEditorModule.CreateSingleProperty(Actor, InPropertyName, FSinglePropertyParams());
TSharedPtr PropertyHandle = SinglePropertyView->GetPropertyHandle();

// Reset to default
PropertyHandle->ResetToDefault();
}
}`Please let me know if this solution works for you or if you need any further assistance.

Best regards,

Vitor

it worked perfectly, thanks!