I feel I am just doing something really stupid, but I cannot make my custom actor movable in the editor or in the game.
The actor directly inherits from AActor
.
I have tried using a UStaticMeshComponent
as RootComponent
as well as a USceneComponent
with the mesh being a child of the scene (as I found some posts suggesting that a USceneComponent
would be required). All of the components are stured as EditAnywhere
and BlueprintReadWrite
properties of the actor:
this->SceneRoot = this->CreateDefaultSubobject<USceneComponent>(TEXT("Scene Root"));
this->SceneRoot->Mobility = EComponentMobility::Type::Movable;
this->CoordinateSystemMesh = this->CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Coordinate System"));
this->CoordinateSystemMesh->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
this->CoordinateSystemMesh->Mobility = EComponentMobility::Type::Movable;
this->CoordinateSystemMesh->SetGenerateOverlapEvents(false);
this->CoordinateSystemMesh->SetSimulatePhysics(false);
this->CoordinateSystemMesh->SetStaticMesh(Mesh);
this->CoordinateSystemMesh->SetRelativeScale3D(FVector(1.0f / 50.0f));
this->CoordinateSystemMesh->AttachToComponent(this->SceneRoot, FAttachmentTransformRules::KeepRelativeTransform, TEXT("Coordinate System"));
this->SetRootComponent(this->SceneRoot);
The problem is that (in both cases)
- If I try to change the position of the actor at runtime (i.e. outside the constructor in methods like
BeginPlay
) usingSetActorLocation
orSetActorLocationAndRotation
, the methods have no effect and returnfalse
. - In the editor, my actor shows the transform gizmo, but if I move it somewhere else, it snaps back once I release the mouse button.
- In the editor, if the actor itself is selected, the transform does not show up. I need to select the root component to see the transform. For all other actors (e.g.
StaticMeshActor
), selecting the actor itself shows the transform of the root component in the details view, so I guess this is a symptom of the problem.
What do I need to do to fix that? My main goal is that SetActorLocationAndRotation
works at runtime such that the actor itself can be moved regardless of the root component that is set (provided one is set).
Thanks in advance,
Christoph