Download

UE4 Documentation wrong? (PawnMovementComponent)

Problem
I have created a pawn wich is controlled by a custom player controller. At the moment I move the pawn like this:

  1. FVector NewLocation = GetActorLocation();
  2. NewLocation += GetActorForwardVector() * (SpeedLvL * Speed) * DeltaTime;
  3. SetActorLocation(NewLocation);

This part is exectuted every Tick. But when I move my pawn like this it obviously “ignors” collision.

So I’ve implemeted a PawnMovementComponent by following this documentation (Step 2 & 3):

https://docs.unrealengine.com/latest/INT/Programming/Tutorials/Components/index.html

In the documenation the Input is passed to the MovementComponent like this:

  1. void ACollidingPawn::MoveForward(float AxisValue)
  2. {
  3. if (OurMovementComponent && (OurMovementComponent->UpdatedComponent == RootComponent))
  4. {
  5. OurMovementComponent->AddInputVector(GetActorForwardVector() * AxisValue);
  6. }
  7. }

After I’ve followed this steps and wanted to test my code the if statement doesn’t become true. Splitting it into:

  1. void ACollidingPawn::MoveForward(float AxisValue)
  2. {if (OurMovementComponent){
  3. GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Yellow, “Step 1 done”);
  4. if (OurMovementComponent->UpdatedComponent == RootComponent)
  5. {
  6. GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Yellow, “Step 2 done”);
  7. OurMovementComponent->AddInputVector(GetActorForwardVector() * AxisValue);
  8. }
  9. }
  10. }

Showed me that the second if (OurMovementComponent->UpdatedComponent) is not == the RootComponet, so this part fails. I initialize the OurMovementComponent in the constructor like this:

  1. OurMovementComponent = CreateDefaultSubobject<UCollidingPawnMovementComponent>(TEXT(“CustomMovementComponent”));
  2. OurMovementComponent->UpdatedComponent = RootComponent;

Oh and by the way my RootComponent looks like this:

  1. CollisionSphere = CreateDefaultSubobject<USphereComponent>(TEXT(“Collision Sphere”));
  2. RootComponent = CollisionSphere;

I have also tried the second if statement like this to check if there is something initialized in UpdatedComponent

  1. if (OurMovementComponent->UpdatedComponent->GetName() == “Collision Sphere”)

This test was true. So I think there must be something assigned to UpdatedComponent.

When you have any idea what I am doing wrong or what is wrong with documentaion tell me. :slight_smile:

PS: Sorry for the Clickbait :smiley: