GetAttachParent return null in PostEditChangeProperty

Hello! I am writing component which rotate it parent component (attachment):

void USpinnerComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

#if WITH_EDITOR
	if (!PreviewInEditor) {
		return;
	}
#endif
	USceneComponent* parent = GetAttachParent();
	if (parent) {
		/// do something here
		 parent->AddLocalRotation(rotation);
	}
}

And this work fine.
But when some property changed I need to save parent state but I can not reach my parent any more:

#if WITH_EDITOR
void USpinnerComponent::PostEditChangeProperty(FPropertyChangedEvent & e)
{
	Super::PostEditChangeProperty(e);
	if ( e.GetPropertyName() == GET_MEMBER_NAME_CHECKED(USpinnerComponent, PreviewInEditor)) {
		USceneComponent* parent = GetAttachParent();
		if (!parent)
			return;
		if (PreviewInEditor) {
			BeforePreview = parent->RelativeRotation;
		}else{
			parent->ResetRelativeTransform();
		}
	}
}
#endif

Parent is ALWAYS null, even more in debugger I can see that my object name is “TRASH_SpinnerComponent” or “Spinner_GEN_VARIABLE” while in TickComponent name is always “Spinner”. And I have only one instance of this component in scene. What the hell is happening?

Hi anonymous_user_d4aadacc
I have same problem. So i put my code before Super::PostEditChangeProperty.
Then is work.

There are two things going on here.

The first has to do with the TRASH case. It looks like you have experienced a Blueprint Reconstruction. When any property in an Actor Blueprint instance is modified then all Components in that Actor is destroyed and created from the Blueprint. This happens in Super::PostEditChangeProperty. So by the time execution return to your subclass’ PostEditChangeProperty the object has already been destroyed. The solution is, as Mellos said, to apply your changes first and then let Unreal Engine do it’s work.

The second is related to the GEN_VARIABLE case. When editing in the Blueprint editor, i.e. the Blueprint itself and not an instance, there there is not real Actor yet and the attach hierarchy has not been created. What you see are template Components owned by SCS (Simple Construction Script) nodes, and they have a separate parent / child relationship with their own transform hierarchy. You need to find your UBlueprint parent somewhere in the Outer chain, get the SimpleConstructionScript member from that, which has GetAllNodes, which will give you the USCS_Nodes that you can manipulate.