So, this is probably something stupid that I’m just not wrapping my head around, but I’ve got really baffling behavior in my example application that I haven’t been able to figure out. This isn’t just a C++ problem, since it includes Blueprint as well, but I suspect that if I were trying to do what I’m doing with Blueprint in C++, I’d get the same outcome.
I’m working with an example game that is very simple - there’s a widget object generated in the level script that creates a button and two score counters (one for “my score” and one for “their score”). When a player clicks the button in their client, they increment their score by one and both clients should update to reflect the change in scores. However, the behavior I’m seeing when I test is that one of the clients can increment score while the other can’t, instead generating a warning:
LogNet: Warning: UIpNetDriver::ProcessRemoteFunction: No owning connection for actor NEPlayerController_0. Function Server_ScoreButtonPressed will not be processed.
So here’s what I’m doing. On my player controller, I’ve got the following function:
.h:
UFUNCTION(Server, Reliable, WithValidation, BlueprintCallable) void Server_ScoreButtonPressed(int32 PlayerID);
.cpp:
void ANEPlayerController::Server_ScoreButtonPressed_Implementation(int32 PlayerId)
{
UE_LOG(LogTemp, Verbose, TEXT("Incrementing Player Score For Player: %i"), PlayerId);
ANetworkExampleGameState* gameState = Cast<ANetworkExampleGameState>(UGameplayStatics::GetGameState(GetWorld()));
if (gameState != nullptr)
{
int32 score = gameState->IncrementScore(PlayerId, 1);
Client_TriggerScoreChangedEvent(PlayerId, score);
}
}
The UI itself is scripted in Blueprint because the whole point of this example game was to explore how easy it was to let designers handle UI in Blueprint while actual game logic happens on the C++ side. I’ve got a single widget that contains the whole UI (all three elements of it), with the following logic for constructing itself and actually responding to a button press:
So I’m starting two clients and a separate server on my machine for test purposes. I’ve arbitrarily chosen to label the one that starts directly in editor Player 1 and the one that opens in a new editor window Player 2. When Player 1 clicks the button, everything works. When Player 2 clicks the button I get the “No owning connection for actor NEPlayerController_0” warning and nothing happens (which, since the server isn’t executing the function, makes sense). Can anyone tell me what I’ve done wrong?
Thanks.