No owning connection for actor ... Function Server_SetPlayerName will not be processed.

Hi!

I’m learning multiplayer games with Unreal 5.0.3.

I have two players on a listen server player. The first player creates a Session and another player joins it. This is the log I get when the player joins the session:

LogTemp: Warning: [ ASessionTestPlayerState::OnRep_PlayerName ] Melnibone-C3C47F184F
LogTemp: Warning: [ ASessionTestCharacter::BeginPlay - Sever]
LogTemp: Warning: [ ASessionTestGameModeBase::PostLogin ] 
LogNet: Join succeeded: Melnibone-C3C47F184F
LogTemp: Warning: [ ASessionTestPlayerState::OnRep_PlayerName ] Server Player
LogTemp: Warning: [ ASessionTestCharacter::BeginPlay - Client]
LogTemp: Warning: [ ASessionTestCharacter::BeginPlay - Client]
LogNet: Warning: UNetDriver::ProcessRemoteFunction: No owning connection for actor BP_ThirdPersonCharacter_C_1. Function Server_SetPlayerName will not be processed.
LogTemp: Warning: [ ASessionTestPlayerState::OnRep_PlayerName ] Melnibone-C3C47F184F
LogTemp: Warning: [ ASessionTestCharacter::Server_SetPlayerName_Implementation ]
LogTemp: Warning: [ ASessionTestPlayerState::OnRep_PlayerName ] Client Name
LogTemp: Warning: [ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation Init]
LogTemp: Warning: [ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation End - Client Name]
LogTemp: Warning: [ ASessionTestPlayerState::OnRep_PlayerName ] Client Name
LogTemp: Warning: [ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation Init]
LogTemp: Warning: [ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation End - Client Name]
LogTemp: Warning: [ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation Init]
LogTemp: Warning: [ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation End - Client Name]
LogTemp: Warning: [ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation Init]
LogTemp: Warning: [ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation End - Client Name]

I get this warning:

LogNet: Warning: UNetDriver::ProcessRemoteFunction: No owning connection for actor BP_ThirdPersonCharacter_C_1. Function Server_SetPlayerName will not be processed.

Probably, but I don’t know, the ACharacter::BeginPlaymethod is run too early. But, the method AGameModeBase::PostLogin has already ran when the BeginPlay runs.

This is the code:

void ASessionTestCharacter::BeginPlay()
{
	Super::BeginPlay();

	if (HasAuthority())
	{
		UE_LOG(LogTemp, Warning, TEXT("[ ASessionTestCharacter::BeginPlay - Sever]"));
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("[ ASessionTestCharacter::BeginPlay - Client]"));
	}	
	
	if (GEngine->GetNetMode(GetWorld()) == NM_Client)
	{
		USessionTestGameInstance* MyGameInstance =
			Cast<USessionTestGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));

		if (MyGameInstance)
		{
			Server_SetPlayerName(
				MyGameInstance->GetPlayerName(),
				false);
		}
	}
}

void ASessionTestCharacter::Server_SetPlayerName_Implementation(
	const FString& NewPlayerName,
	bool bNameChange)
{
	UE_LOG(LogTemp, Warning, TEXT("[ ASessionTestCharacter::Server_SetPlayerName_Implementation ]"));

	if (HasAuthority())
	{
		AGameModeBase* GM = GetWorld()->GetAuthGameMode();
		GM->ChangeName(GetController(), NewPlayerName, bNameChange);
	}
}
void ASessionTestGameModeBase::PostLogin(APlayerController* NewPlayer)
{
	Super::PostLogin(NewPlayer);
	UE_LOG(LogTemp, Warning, TEXT("[ ASessionTestGameModeBase::PostLogin ] "));

	if ((!bOptionsRead) && !OptionsString.IsEmpty())
	{
		FString PlayerName = UGameplayStatics::ParseOption(OptionsString, "Name");

		ChangeName(NewPlayer, PlayerName, true);

		bOptionsRead = true;
	}
}

void ASessionTestPlayerState::OnRep_PlayerName()
{
	UE_LOG(LogTemp, Warning, TEXT("[ ASessionTestPlayerState::OnRep_PlayerName ] %s"), *GetPlayerName());

	ASessionTestCharacter* OwningCharacter =
		Cast<ASessionTestCharacter>(GetPawn());

	if (OwningCharacter)
	{
		OwningCharacter->Server_ShowPlayerName();
	}
}

void ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation()
{
	UE_LOG(LogTemp, Warning, TEXT("[ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation Init]"));

	//APlayerState* PlayerState = GetPlayerState();
	ASessionTestPlayerState* CustomPlayerState = 
		Cast<ASessionTestPlayerState>(GetPlayerState());

	if (CustomPlayerState)
	{
		OverHeadName->SetText(FText::FromString(CustomPlayerState->GetPlayerName()));

		UE_LOG(LogTemp, Warning, TEXT("[ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation End - %s]"), *CustomPlayerState->GetPlayerName());
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("[ ASessionTestCharacter::MulticastRPCShowPlayerName_Implementation End]"));
	}
}

The problem is that BP_ThirdPersonCharacter_C_1 doesn’t have a PlayerController yet.

I have tried the method void ASessionTestCharacter::PossessedBy(AController* NewController) it doesn’t appear the warning because that method never runs.

How can I fix this code?

Thanks!

1 Like

You should not attempt to call any Server RPC from an Actor before the Owner is valid in OnRep_Owner and HasLocalNetOwner is true.

Furthermore you should favor replicated variables rather than MulticastRPC’s when dealing with state changes (changes that should persist).

I don’t understand that.

I’m using PlayerState and setting the text in a UTextRenderComponent, this is why I’m using Multicast.

RPC’s are only received by whoever is connected at the time it is sent.

Replicated variables are sent out even if someone joins the game 10 seconds after the MulticastRPC was called.

MulticastRPC’s are normally only used for effects while they happen like explosion sounds or instant messages that only matter in the moment it happened.

Yes, but I still don’t know how to solve the problem.

I am new. I’m learning. This is the first time I’ve done this. Don’t expect me to know what you’re talking about if you talk to me like I’m already an expert.

If HasLocalNetOwner is false on BeginPlay don’t bother calling the Server RPC.

Call it from OnRep_Owner if HasLocalNetOwner is true.

Then you are correctly calling GameMode->ChangeName.

This calls PlayerState->SetPlayerName which sets a replicated variable server-side

Client-side (and listen-server-side) you can use the PlayerState->OnRepPlayerName function to update UI etc rather than using your own MulticastRPCShowPlayerName function.

OK. Thanks.

Now, I’ve understood everything.

Thanks.

With your answer, I don’t see that warning again. I have also removed the multicast. But know I get this:

The right window is listen server’s player. The left window is the client.

Before modifying the code with your answer I got this:

I’ll continue watching videos about this.