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