I have AI characters spawned when a player logs in and get possessed by PlayerController.
Once the AI spawned on server (a listen server) I set the PlayerController as their owner. Like every player has a companion AI.
I override GetNetConnection
of the AI character class in order to let it get connection from its owner (the PlayerController) so I can call RPC on it.
UNetConnection* ACompanionCharacter::GetNetConnection() const
{
if (GetOwner() && GetOwner()->IsA<APlayerController>())
{
return GetOwner()->GetNetConnection();
}
return Super::GetNetConnection();
}
I have some client RPC methods on the AI character class. When I call them on the server, if the ai is owned by a player connected as client, they work as expected.
But if I call them on a AI which is owned by a player playing as listen server, they doesn’t run on the server.
The table in the docs says that if I call client RPC on server they will execute on server. Then why mine does not work?