Rotation Replication Wrong

Hello,

I’m trying achieve placing a particle system in the location the player is looking, it works good but the rotation angles are ignored during replication - it seems to only take into account the location vectors. If somebody can look at the code and tell me what I’m doing wrong I’d appreciate it.

void AWepAttach_Sights::dostuff()
{
	TArray<AActor*> ignoredActors;
	ignoredActors.Add(this);
	ignoredActors.Add(GetOwner());
	ignoredActors.Add(MyPawn);

	FHitResult Hit(ForceInit);

	static FName LaserTrace = FName(TEXT("LaserTrace"));
	FCollisionQueryParams RV_TraceParams(LaserTrace, true, GetOwner());

	RV_TraceParams.bReturnPhysicalMaterial = false;
	RV_TraceParams.bTraceComplex = false;
	RV_TraceParams.bTraceAsyncScene = true;
	RV_TraceParams.AddIgnoredActors(ignoredActors);

	const FRotator viewRot = MyPawn->GetViewRotation().GetNormalized();
	const FVector StartDir = MyPawn->GetPawnViewLocation();
	const FVector Direction = MyPawn->GetPawnViewLocation() + FRotationMatrix(viewRot).GetScaledAxis(EAxis::X) * 2000;

	GetWorld()->LineTraceSingleByChannel(Hit, StartDir, Direction, ECC_Visibility, RV_TraceParams);

	if (Hit.bBlockingHit)
	{
#ifdef DEBUG_MODE
		DrawDebugLine(GetWorld(), StartDir, Direction, FColor(255, 0, 0), false, 2.0f, 0, 3.0f);
#endif	
	}

	if (Role == ROLE_AutonomousProxy)
	{
		Serverdostuff();
	}
}

bool AWepAttach_Sights::Serverdostuff_Validate()
{
	return true;
}

void AWepAttach_Sights::Serverdostuff_Implementation()
{
	dostuff();
}

Sorry, should have worded it better. Yes that’s what I’m saying, at least I’m assuming I’ve set the rotation variable to replicate.

While that’s some insightful information and I appreciate it, I’m not directly sending a basic variable, I’m asking it to replicate the clients GetViewRotation to the server so that it can set the worldposition of the Particle Component. If the Location is replicating, then it implies that I’m doing the right process, but for some reason the angles are not.

Are you saying that the rotation of your pawn, on the client, is not being replicated to the server, even though you’ve set the rotation variable to replicate?

Under no circumstances do variables replicate from the client to the server.

To set a variable to replicate (from server to client) you have to marked it as Replicated or ReplicatedUsing = function in its UPROPERTY macro and then add it to the GetLifetimeReplicationProperties() function.

The character movement component should update the server, though, if you’re using a character. Are you using the ACharacter class?

If not, you have 2 options:

  • Send the location, rotation and so on to the server every tick using an RPC.
  • Send the current look direction as a parameter in your server function.

A warning with that second option, rotator axes are compressed down to bytes when replicated, so they lose a lot of their granularity. If you want accurate rotation, send the pitch and yaw as separate parameters as floats.

How are you doing doing the replication?

The same way Shooter Game does SetRunning or EquipWeapon.

If you look at the code in the first post, the structure of how EquipWeapon for example is done, is in the same form. dostuff(); is then called in Tick.

Assume that not everyone is familiar with shooter game or has a copy of it set up to look at…

So you’ve got a server rpc function that sends your location and rotation to the server?

Sorry if I wasn’t clear before, but that’s what I meant.