Programmatically set blueprint defaults in editor

Hello,

I need to programmatically assign default values to a blueprint’s parameters in the editor via c++ (at editor time).
The idea is to change the default values, recompile the blueprint and then all instances of it will automatically update to the new values.

I have the code below, it runs, but the default value doesn’t change in the editor. If I read back the set value it is correct.

void UEditBlueprint::TestSetPropertyDefault(UBlueprint* aBlueprint)
{
	UBoolProperty* boolProp = Cast<UBoolProperty>(aBlueprint->GeneratedClass->FindPropertyByName(FName(TEXT("SetPropertyTestBool"))));
	boolProp->SetPropertyValue_InContainer(aBlueprint, true);
		
	// Test read back
	bool propVal = boolProp->GetPropertyValue_InContainer((UObject*)(aBlueprint));

	aBlueprint->MarkPackageDirty();
	FKismetEditorUtilities::CompileBlueprint(aBlueprint);
}

It is needed for an automation pipeline, so ideally I want to solve it like this, not with setting values of every reference in every level. This example is for a bool, the actual parameter will be an array of actors which are created programmatically.

I have tried many different approaches and am out of ideas. I think I might be working on a wrong reference or perhaps missing a call which propagates the change (to the UI)?

1 Like

If I don’t misunderstand what you’re trying to achieve, I believe you can change the default values simply by setting any values on Class->GetDefaultObject(). If I remember correctly, it’ll be propagated back to the editor immediately.

Thanks that did the trick, I needed to call the above code on the default object.
The change is reflected in the editor, but not propagated to the instances, I will look into that now, as it does work when setting manually.