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?