x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Spawned pawn doesn't respond to AddMovementInput

I've modified the template TopDown controller to work nicely on multiplayer, and I set it up so if I touch a trigger, I call a SpawnActor function (as APawn), and then I call a function to possess it and to Destroy the original actor.

Everything works great, it gets destroyed, the new one gets spawned and possesed, but suddenly the click-to-move system doesn't work anymore. I added debug lines, and it gets the clicks correctly (position, direction, distance), but the new object just won't move.

The code for the SpawnActor:

APawn* playerPawn = world->SpawnActor(heroC, FVector(0, 0, 150), FRotator::ZeroRotator, SpawnParams);

The code for the movement:

 APawn* const Pawn = GetPawn();
     if (Pawn)
     {
         Debug("Pawn found");
         Distance = FVector::Dist(clickLocation, Pawn->GetActorLocation());
         Direction = (clickLocation - Pawn->GetActorLocation()).Rotation().Vector();
         
         Debug(Direction.ToString());
         Debug(FString::FromInt(Distance));
         Pawn->AddMovementInput(Direction, Distance);}

Product Version: Not Selected
Tags:
more ▼

asked Mar 09 '15 at 10:16 PM in C++ Programming

avatar image

Kashbel
1 1 2 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

5 answers: sort voted first

Adding a movement component is supposed to work, but it hasn't for me, so I suggest inheriting from DefaultPawn instead of Pawn.

more ▼

answered Apr 10 '15 at 12:10 PM

avatar image

bilal
0 1 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Need to set the AddInput to true, try this.

   Pawn->AddMovementInput(Direction, Distance, True);}

more ▼

answered Apr 13 '15 at 01:22 PM

avatar image

RickTorr2494
9 1 2 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Have you given a value to MovementComponent in your custom APawn object's constructor and set the MovementComponent's UpdatedComponent to the root component of your custom pawn?

 // Create dummy root scene component.
 DummyRoot = CreateDefaultSubobject<USceneComponent>(TEXT("Dummy0"));
 RootComponent = DummyRoot;
 
 /* Attach stuff like static meshes to the dummy root here */
 
 // Create the movement component and set the updated component for it.
 MovementComponent = CreateDefaultSubobject<UPawnMovementComponent, UFloatingPawnMovement>(ADefaultPawn::MovementComponentName);
 MovementComponent->UpdatedComponent = DummyRoot;


A good way of figuring out stuff like this is to look through code for similar classes in the engine. In this case, DefaultPawn's source code.

more ▼

answered May 25 '15 at 11:19 PM

avatar image

TheUtahTeapot
1 1 2 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I've encountered this, am I right in assuming it does work on the server, but not on a remote client?

If so, the issue is caused by the fact that the server notifies the client that it is possessing a new pawn, but that pawn isn't replicated to the client yet. Although it may seem weird, try overriding OnRep_Pawn() in your controller class like this, this enforces the client to acknowledge the pawn possession right when the new pawn is initialized client-side.

MyPlayerController.h:

 virtual void OnRep_Pawn() override;

MyPlayerController.cpp:

 void AMyPlayerController::OnRep_Pawn()
 {
     Super::OnRep_Pawn();
     if (!HasAuthority() && GetPawn() != AcknowledgedPawn)
         ChangeState(NAME_Inactive);
 }
more ▼

answered May 27 '15 at 02:19 PM

avatar image

Zhi Kang Shao
496 9 11 30

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I've encountered this, am I right in assuming it does work on the server, but not on a remote client? If so, the issue is caused by the fact that the server notifies the client that it is possessing a new pawn, but that pawn isn't replicated to the client yet. Although it may seem weird, try overriding OnRep_Pawn() in your controller class like this, this enforces the client to acknowledge the pawn possession right when the new pawn is initialized client-side.

Note: There is a retry mechanism in place that should trigger

MyPlayerController.h:

 virtual void OnRep_Pawn() override;

MyPlayerController.cpp:

 void AMyPlayerController::OnRep_Pawn()
 {
     Super::OnRep_Pawn();
     if (!HasAuthority() && GetPawn() != AcknowledgedPawn)
         ChangeState(NAME_Inactive);
 }
more ▼

answered May 27 '15 at 02:19 PM

avatar image

Zhi Kang Shao
496 9 11 30

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question