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::BeginPlay
method 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!