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;
};

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 :slight_smile:

Posted the .h in the question.

Here’s the validate function.

bool UShipMovement::Server_UpdateCustomMovementState_Validate(FVector InControlInputVector, FRotator InControlInputRotation)
{
	return true;
}

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.

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.