Download

AddMovementInput not taken into account unless Pawn is selected in World Outliner

So this has been puzzling me for the last hour, and I still don’t understand what’s happening.

My setup is that the PlayerController receives the input, then use an interface to transfer the float value to the currently possessed pawn.

Now, I exposed and double-checked everything, the Pawn is correctly possessed, the float value is correctly transferred and the function is executed. I can see with logs that there’s no issue at this level. However, it looks like AddMovementInput doesn’t do anything at all unless the pawn is selected in the World Outliner in the editor. If I launch the game outside of PIE or I don’t select anything in the World Outliner, pawn doesn’t move at all.



void ATWSpiritCam::MoveCameraForward(float ScaleValue)
{
    if (!bCanMoveCamera)
        return;

    FVector DirectionVector = this->GetActorForwardVector();
    DirectionVector.Set(DirectionVector.X, DirectionVector.Y, 0.0f);
    ULog::Number(ScaleValue, "PawnReceivedInput:");
    this->AddMovementInput(DirectionVector, ScaleValue);
}


The logging function works, selected or not, and the ScaleValue is correct. Everything works as expected as long as the Pawn has been selected at least once in the World Outliner. The Pawn inherits from ACharacter class, so MovementComponent is there and working.

Any ideas on what I may be missing? I don’t see anything related to focus or something like that.

Ha I’m getting somewhere…so actually AddMovementInput works, I can see it from GetTransform(). However only the root is moving, although the Camera is attached to the Capsule Component that is root. When I select the pawn in the editor, the camera follows the root transform as expected.

I’m getting closer!

Okay I’m officially stupid, but I’ll leave this here in case it can help someone!

I had forgotten that I commented out the “AttachToComponent” when I created the camera post-initialization…

So morale of the story: don’t trust the editor. Even if it seems that a component is attached to the root, it may not be!

IF we don’t attach any component to the root, it automatically gets garbage collected by UEngine