Setting owner not working on all clients

I have this BP_ProjectileLauncher class the fires projectiles. I’m testing this with 2 clients, using a dedicated server setup. When the game starts Setup Launcher is called which sets the owner of the launcher to the player controller.

Setup Launcher is only called on the server. At the end of the Setup Launcher function, the correct owner is printed for each client. But for some reason when I attempt to call a server RPC from the BP_Projectile launcher it works for one client, but is dropped on the other.

When I print the owner before calling the server RPC one client prints the correct owner, but the other is just blank. I don’t understand how this is working for one client but not the other.

The only reason it appears to print the owner on both clients in SetupLauncher is because PrintString is setup to print on all viewports, otherwise you wouldn’t see any print strings done on dedicated server (because it has no visible window).

If you look directly into the Output Log, you should see that the clients are not actually printing anything in SetupLauncher, only the server is :

Server: [BP_ProjectileLauncher_C_0] PlayerController_C_0
Server: [BP_ProjectileLauncher_C_1] PlayerController_C_0

And you can also see that both launchers have the same PlayerController assigned.
This is becaue you are using generic node GetPlayerController(0) which is unfit for server code. You need to find a way to reach the correct playercontroller. Maybe the owner of the BP_ProjectileLauncher itself ? Or maybe the launcher is owned by the pawn/character, then you can use GetOwner->Cast(Pawn)->GetController ?
If you don’t know, look into your code that spawns the ProjectileLauncher. In the SpawnActor node there is a pin to pass the Owner. You should probably pass the pawn that owns the weapon in there.

I just switched it to GetOwner of the pawn and everything works as expected. Thank you!

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