Help me understand networked movement. Looking to network player character head rotation.

Hey all,

I want to extend the basic networked movement so I can get the angle the camera is pointing and translate that via the Animation Blueprint to animate the character’s head rotation.

I have some example pieces of code where I network events such as weapon fire, health, but when it comes to head rotation I don’t want to implement something that’s just going to congest the event list. I see there’s a fair bit of code to manage movement to ensure it’s optimized so I guess I’d need to either replicate something closer to that, or find out that it’s already handled and I missed it or there’s a totally different way of networking that information.

Can someone point me to an example where there’s code that does this?

I noticed in the blueprint for the character that there’s an option to use the controller rotation pitch, however enabling that automatically causes the character to rotate on that axis. This at least tells me that the information is there to network, and I presume fairly optimally, but then presents the issue if how to stop it from making the character rotate on that axis.

2020-08-23 22_25_41-PooleExp01 - Unreal Editor.png

This is some basic code I setup to replicate the forward vector of the camera, which I tested by drawing a debug arrow. It works, but I’m not sure if the solution is sub-optimal. I haven’t investigated trying to harness enabling controller rotation as above yet. For now this looks like it’s something I can work with.

CharacterBase.h



protected:
UPROPERTY(BlueprintReadOnly, ReplicatedUsing=OnRep_SetHeadDirection)
FVector HeadDirection;

UFUNCTION()
void OnRep_SetHeadDirection();
UFUNCTION(Server, Unreliable)
void SetHeadDirection(FVector NewDirection);
void SetHeadDirection_Implementation(FVector NewDirection);

public:
*/* Property replication ** * Contains all properties that need to be replicated for the life time of the session */ *
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;


CharacterBase.cpp



void APLCharacterBase::LookUp(float value)
{
       if(IsLocallyControlled() && value !=0.0f)
       {
              APawn::AddControllerPitchInput(value);
              SetHeadDirection(CameraComp->GetForwardVector());
       }
}

void APLCharacterBase::SetHeadDirection_Implementation(const FVector NewDirection)
{
HeadDirection = NewDirection;
}

void APLCharacterBase::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
      Super::GetLifetimeReplicatedProps(OutLifetimeProps);

      // Replicate direction
      DOREPLIFETIME(APLCharacterBase, HeadDirection);
}


You most likely also want to skip replication on the owner of the character. You can do that with the conditional replication macro: https://docs.unrealengine.com/en-US/…ons/index.html