Edit blueprint defaults after editing UProperty

Hello there.

I’d like to be able to edit default values (of properties) in blueprint. That blueprint derives from my class that has two variables declared as follows:

UPROPERTY(EditDefaultsOnly, Category = "Configuration")
int32 SomeVariable;

UPROPERTY(EditDefaultsOnly, Category = "Configuration")
TArray<int32> SomeArray;

I also overrided OnConstruction() function in that class like:

virtual void OnConstruction(const FTransform& Transform) override;

And then, in my class implementation i’m doing this:

void MyClass::OnConstruction(const FTransform& Transform)
{
	Super::OnConstruction(Transform);

	SomeArray.Empty();
	for (int32 i = 0; i < SomeVariable; ++i)
	{
		SomeArray.Add(i);
	}

	int32 Count = SomeArray.Num();
	int32 asd = 0; // just for purposes of setting up a breakpoint    
}

After getting this done, I tried to test if that works and unfortunately nothing happens. I’m changing value of ‘SomeVariable’ in my blueprint’s defaults and my array doesn’t get changed at all. However, when I set a breakpoint on ‘int32 asd = 0;’ line, I can clearly see, that Count variable has proper value, thus the array is actually set, but I simply can’t see the changes in defaults editor window/panel.

Another aproach:

I dug a little and I tried a bit more complex approach. I’ve found somewhere in UE4’s code functions for setting values on specific properties. I adjusted the code, a bit (so I could work on smth easier for starters).

New stuff in header:

UPROPERTY(EditDefaultsOnly, Category = "Configuration")
int32 AnotherVal;

UPROPERTY(EditDefaultsOnly, Category = "Configuration")
int32 SomeVariable;

New stuff in .cpp:

FString PropName = FString("AnotherVal");
for (TFieldIterator<UIntProperty> PropertyIt(GetClass()); PropertyIt; ++PropertyIt)
{
	UIntProperty* Prop = *PropertyIt;

	if (Prop && Prop->GetName() == PropName)
	{
		int32 Val = Prop->GetPropertyValue(Prop->ContainerPtrToValuePtr<int32>(this));
		if (Val != FirstVal)
		{
			PreEditChange(Prop);

			AnotherVal = FirstVal;	
			Property->SetPropertyValue(Prop->ContainerPtrToValuePtr<int32>(this), FirstVal);

			PostEditChange();
		}    
		return;
	}
}

Above .cpp part is obviously in OnConstruction(…) function. The goal in this case is to simply copy value from one (FirstVal) UProperty to another (AnotherVal) and refresh editor’s UI to see the changes.

Unfortunately, this solution doesn’t work either. I’ve tested it a bit and I can tell that finding proper property works, the value is actually changed and the editor knows about that the value has changed because it fires OnConstruction function again however, UI remains unchanged.

Could anyone help me with getting this done? Firstly for this simple case with 2 int32 variables, but eventually, I’d want to make it work with arrays as well as this is my main goal in here.

Oh, and I’m using UE4.10.0.

Thanks in advance. :]


Edit:
Inspired by Begounet’s reply I made this:

.h

#if WITH_EDITOR
	virtual void PostEditChangeProperty(struct FPropertyChangedEvent& e) override;
#endif

.cpp

#if WITH_EDITOR
void AMyClass::PostEditChangeProperty(struct FPropertyChangedEvent& e)
{
	FName PropertyName = (e.Property != NULL) ? e.Property->GetFName() : NAME_None;

	if (PropertyName == GET_MEMBER_NAME_CHECKED(AMyClass, SomeVariable))
	{
		SomeArray.Empty();
		for (int32 i = 0; i < SomeVariable; ++i)
		{
			SomeArray.Add(i);
		}
	}

	Super::PostEditChangeProperty(e);
}
#endif

And this works! ^^

Overriding PostEditChangeProperty cannot help you ?

Works! Thanks! :smiley:

If you’d convert your comment into an answer I could mark this question as answered already.

Thanks again man! :]