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"

UPawnMovement Velocity Replication

Hopefully this is a quick solution, driving myself crazy trying to figure this out.

I'm inheriting from the UFloatingPawnMovement for a custom movement component and replicating my input state to the server as seen below.

 void UCustomMovement::PreTick(float DeltaTime)
 {
     APawn* MyOwner = UpdatedComponent ? Cast<APawn>(UpdatedComponent->GetOwner()) : NULL;
 
     if (MyOwner && MyOwner->IsLocallyControlled())
     {
         Server_UpdateCustomMovementState(ControlInputVector, ControlInputRotation);
     }
     else
     {
         ControlInputVector = CustomMovementState.ControlInputVector;
         ControlInputRotation = CustomMovementState.ControlInputRotation;
     }
 }
 
 void UCustomMovement::Server_UpdateCustomMovementState_Implementation(FVector InControlInputVector, FRotator InControlInputRotation)
 {
     ControlInputVector = InControlInputVector;
     ControlInputRotation = InControlInputRotation;
 
     CustomMovementState.ControlInputVector = InControlInputVector;
     CustomMovementState.ControlInputRotation = InControlInputRotation;
 }


Most frustrating part is that I can see the ControlInputVector on the server changing but the Velocity of the Pawn on the server stays the same. What am I doing wrong? Why does the Pawn move fine locally but not on the server?

Edit: Including the .h

 USTRUCT()
 struct FReplicatedCustomMovementState
 {
     GENERATED_USTRUCT_BODY()
 
     UPROPERTY()
     FVector ControlInputVector;
 
     UPROPERTY()
     FRotator ControlInputRotation;
 };
 
 /**
  * 
  */
 UCLASS()
 class UCustomMovement : public UFloatingPawnMovement
 {
     GENERATED_UCLASS_BODY()
 
     virtual void PreTick(float DeltaTime);
     virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) OVERRIDE;
 
     UFUNCTION()
     void SetInputRotation(FRotator Rotation);
 
     UFUNCTION(Reliable, Server, WithValidation)
     void Server_UpdateCustomMovementState(FVector InControlInputVector, FRotator InControlInputRotation);
     virtual FVector ConsumeInputVector() OVERRIDE;
 
 public:
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = CustomMovement)
     float TurnSpeed;
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = CustomMovement)
     FRotator ControlInputRotation;
 
 protected:
     UPROPERTY(Transient, Replicated)
     FReplicatedCustomMovementState CustomMovementState;
 };

Product Version: Not Selected
Tags:
more ▼

asked Jul 03 '14 at 04:09 AM in C++ Programming

avatar image

HailstoneRyan
714 40 27 54

avatar image Rama Jul 03 '14 at 01:59 PM

can you post your .h as well? How did you even get this to compile ? if you use a server function and _implementation then you also need a _validate as well, as far as I know :)

avatar image HailstoneRyan Jul 03 '14 at 02:26 PM

Posted the .h in the question.

Here's the validate function.

 bool UShipMovement::Server_UpdateCustomMovementState_Validate(FVector InControlInputVector, FRotator InControlInputRotation)
 {
     return true;
 }
avatar image mylkrex Feb 27 '15 at 03:14 PM

Where do you call ‘PreTick’ function? I call it from TickComponent, but will disconnect from server because of too many request at a same time.

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

1 answer: sort voted first

Answered my own question. Should have looked at the source of the FloatingPawnMovement component. Looks like I'll have to roll my own.

 const AController* Controller = PawnOwner->GetController();
 if (Controller && Controller->IsLocalController())
 {
 //VELOCITY RELATED CODE ALL IN HERE
 }

Edit: Confirmed this is the offending code by commenting it out in the engine. I wonder if there's a reason it's limited to local only.

more ▼

answered Jul 03 '14 at 02:52 PM

avatar image

HailstoneRyan
714 40 27 54

(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