My Server and client are being called in IsLocallyControlled()

I am using UE5, within my Tick Function I’m using the if (IsLocallyControlled()) statement, but my authority is still being called within it. I recently added !HasAuthority() to the Statement with an AND, but I feel like LocallyControlled should take care of it by itself right?

void AGoKart::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	//If it's the client not the server
	if (IsLocallyControlled())
	{
		FGoKartMove Move = CreateMove(DeltaTime);

		UnacknowledgedMoves.Add(Move);

		UE_LOG(LogTemp, Warning, TEXT("Role: %s"), *GetEnumText(GetLocalRole()));
		UE_LOG(LogTemp, Warning, TEXT("Queue Length: %d"), UnacknowledgedMoves.Num());

		Server_SendMove(Move);
		SimulateMove(Move);
	}

	DrawDebugString(GetWorld(), FVector(0, 0, 100), GetEnumText(GetLocalRole()), this, FColor::White, DeltaTime);
}

IsLocallyControlled means the vehicle in that particular client is controlled by that instance. If you have one that is the server, then it still has a locally controlled pawn as well so it will be called but should only affect that one pawn. The tick still runs on the server but any code inside that if will not be executed but if you added an else, that would be executed instead.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms