Cant get pawn controller on client side(networking)

Hello, please help, i fount out that get controller for the pawn returns notning if im doing this action from the client.

Im starting to touch the network support of my game, which is RTS. I dont have any authority checks before
“get controller” and cast to the controller. And for some reason doing any kind of “get controller” or “get instigator controller” returns as nothing if im at client side, but everything works if its going from the server.

My single player setup originaly was that the Player controller comunicates with the AI controllers of the pawn via get controller, casting to it and pasing some operations via Interface function. So i want to do the same thing but for networking.

Also I havent yet set or created Game Instance ,Game State or Player State, does that have to do with not being able to get a Pawns controller?

Ok so basically. “Get Player Character” / “Get Player Controller” is a quite bad idea if you work in multiplayer. You probably saw the integer input. If you work with multiplayer you have multiple player characters / player controllers so you need that number.

They only work for single player games as magical “Get this” node.

You somehow need to get the reference from your player to the AI. Personally I would do that by using the Game Mode.

Game Mode has an event “Event Post Login” which will provide you a “Player Controller” reference.

If you spawn in your AI via the game mode instead of placing it in the level you also have a guaranteed OOP legit reference to them.

And from then on you can for every Post Login which gets to play the player controller reference and feed it to your AI.

Cheers

Oh I just realized I forgot something else.

Your AI should only exist on the server. You don’t need it anywhere else. Only the server should know what the AI actually does and calculate that. You only replicate the results (aka units moving, creating a new building, etc).

The clients don’t need the logic that drives the AI itself.

Thank you Erasio,

I will try you aproach and I’ll get back with the updated :slight_smile:

Yes thats what i figured right now.

So now what im doing is making sure that somewhere in the BP logic i have a Authority switch and if its a Client than i send it through the the custom event with the replication option set to (run on server).

Which in turn starts for example “Select unit” Interface that has a AI controller as an input.

Interface fires the event in the AI controller which fires the event inside the controlled Character(Pawn) that changes the visibility of a decal componenet etc.

And I made that Event in the Character(Pawn) replicatable as a “Run from Owning Client” but for some reason it doesnt come back to the client.
It only works on the server side.

How can I specify to make some changes back to the certain Client?

Im reading the RPC documentation and i dont fully understand how do you specify the ownership of the Actor, in my case the player controller indirectly through the AI controller speaks to the Pawn, so how in this situation does the ownership works?

You probably should watch this video series from epic.

Hello Erasio, actualy i did watch them and they dont cover actor owner or replication from server to client sitaution.

After a lot of testing I found that when I stat the game in PIE I have a server and client windows and the Game mode prints me that there are only 2 player controllers (for example - player_controller_1 and player_controller_2) bu the client says that theres only 1 player controller (player_controller_3).

I believe thats why when on the client side i do “SetOwner” node, on the server it is ignored and shows nothing if i try to print the “GetOwner” for the specific, replicatable actor variable.

Ok so in short. By default you only have server → client replication.

The client doesn’t replicate everything to the server. That you have to specify.

For owners this means you have to specify the owner on the server. It will replicate to the right player but you spawn a player controller for every player on the server and another one on each client. It’s not actually the same object that updates itself back and forth.

Do EVERYTHING game related on the server. All you do on clients is handle input, forward it to the server, change visual stuff and maybe if you wanna be fancy do the same calculations as the server so you get rid of the delay while getting the update from the server regularly and updating your scene based on the info you got.

If you want info about other players you should really take a look into the “Player State” since that’s replicated to all players. Also only Server → Client but all player have access to the Player State of all other players (and ofc their own as well).

Thank you Erasio, im getting close though, and you are helping me with that and i appreaciate that.

I understand thats its hard to give a specific points if im not showing the actual BP’s. In case im not going to figure this out ill post in depth my BP setup!