I have a C++ class which extends USceneComponent and adds various other components/functionality. As part of the hierarchy, there are another two nested USceneComponents:
- Root
- - LocatorRoot
- - - Locator
And there are two UPROPERTY’s that can be set in the editor:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FVector LocationOffset;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FRotator RotationOffset;
These properties drive the location/rotation of those SceneComponents using these two lines of code:
LocatorRoot->SetRelativeRotation(RotationOffset);
Locator->SetRelativeLocation(LocationOffset);
So I want the level designers to be able to change these properties in the editor (not in BeginPlay - it needs to be in the editor because it’s important to see how it looks), and the location/rotation values to be updated accordingly.
I understand that placing those two lines in the C++ constructor won’t pick up the changes made on a Blueprint in the editor, but I can’t figure out the correct way to get it working.
I tried:
void UNodeLocatorComponent::PostInitProperties()
{
Super::PostInitProperties();
LocatorRoot->SetRelativeRotation(RotationOffset);
Locator->SetRelativeLocation(LocationOffset);
}
But it does nothing. I also tried:
void UNodeLocatorComponent::PostEditChangeProperty(FPropertyChangedEvent & PropertyChangedEvent)
{
LocatorRoot->SetRelativeRotation(RotationOffset);
Locator->SetRelativeLocation(LocationOffset);
}
But this crashed the editor for calling a pure function.
I would have just created a Blueprint version of the class (so that I could add the logic to the construction script) but when I right click on the C++ class in the editor, “Create C++ derived from NodeLocatorComponent” is not accessible, though I’m not sure why…?
So what is the correct way to this?