It seems that location and rotation functions of UStaticMeshComponent class are not working when you use then inside PostEditChangeChainProperty, PostEditChangeProperty and PostInitProperties. I want to create a private UStaticMeshComponent and expose only location, rotation, static mesh and material properties so that all other options are defined from code (in other words: I want to hide all of the StaticMeshComponent options except these few). Updating the mesh and material inside PostEditChangeProperty works fine. The problem is that calling MyStaticMeshComponent->SetRelativeLocation does not actually change the relative location of the mesh in the blueprint viewport. I have to close the blueprint window, open it again so that it updates correctly. Consider this code:
.H Code
UCLASS(Blueprintable)
class MyGame_API AMyClass: public AActor
{
GENERATED_BODY()
public:
AVanishingObject();
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category=Geometry)
FVector FLocalLocation;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category=Geometry)
FRotator FLocalRotation;
UPROPERTY(BlueprintReadOnly)
class USceneComponent* FSceneComponent;
#if WITH_EDITOR
virtual void PostInitProperties() override;
virtual void PostEditChangeChainProperty(struct FPropertyChangedChainEvent& PropertyChangedEvent) override;
#endif
private:
UPROPERTY()
class UStaticMeshComponent* UStaticMeshComponentBase;
};
CPP Code
// Sets default values
AMyClass::AMyClass()
{
FSceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));
SetRootComponent(FSceneComponent);
FLocalLocation = FVector(0, 0, 0);
FLocalRotation = FRotator::ZeroRotator;
UStaticMeshComponentBase = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshBase"));
UStaticMeshComponentBase->AttachTo(RootComponent);
UStaticMeshComponentBase->SetRelativeLocationAndRotation(FLocalLocation, FLocalRotation.Quaternion(), false, nullptr, ETeleportType::None);
}
#if WITH_EDITOR
void AMyClass::PostInitProperties()
{
Super::PostInitProperties();
UStaticMeshComponentBase->SetRelativeRotation(FLocalRotation.Quaternion(), false, nullptr, ETeleportType::None);
}
void AMyClass::PostEditChangeChainProperty(struct FPropertyChangedChainEvent& PropertyChangedEvent)
{
FName PropertyName = (PropertyChangedEvent.Property != nullptr) ? PropertyChangedEvent.Property->GetFName() : NAME_None;
if (UStaticMeshComponentBase != nullptr)
{
if (PropertyName == FName(TEXT("Roll")) || PropertyName == FName(TEXT("Pitch")) || PropertyName == FName(TEXT("Yaw")))
{
UStaticMeshComponentBase->SetMobility(EComponentMobility::Movable);
UStaticMeshComponentBase->SetRelativeRotation(FLocalRotation.Quaternion(), false, nullptr, ETeleportType::None);
}
if (PropertyName == FName(TEXT("X")) || PropertyName == FName(TEXT("Y")) || PropertyName == FName(TEXT("Z")))
{
UStaticMeshComponentBase->SetRelativeLocation(FLocalLocation, false, nullptr, ETeleportType::None);
}
}
Super::PostEditChangeChainProperty(PropertyChangedEvent);
}
#endif
void AMyClass::BeginPlay()
{
Super::BeginPlay();
if (UStaticMeshComponentBase != nullptr)
{
UStaticMeshComponentBase->SetMobility(EComponentMobility::Static);
}
}
Is there any way to make SetRelativeRotation and SetRelativeLocation work during blueprint editing?