Understanding RPC Events and where they can be called with actor ownership.

So i am setting up multiplayer networking for an RTS style game. I have a unitBase class which is a child of the character class. I have defined the owners of the unit on begin play, and i am trying to ensure that a client can control characters that it owns but i am running into unexpected behavior that i do not understand.

If i call an event ‘clientCallsServer’ from the client in unit base, that then attempts to call ‘ServerEvent’ which is set to be a server only call (which would then issue instructions to an ai to direct the character)

I believe i have set ownership correctly, as i am checking that the owner and player controller match, and they do, and i am checking the role of the controller, which returns as autonomous proxy. These were the conditions i believed would allow Server RPC’s to run, however the server event is never called.

I have managed to issue commands to the AI by routing commands through the player controller class, and the servers instance of player controller then sends commands to the units, which works, but it feels really hacky and my code is spaghettified, so i am not a fan.

What am i missing here?

Cheers for the help in advance, here is the blueprint that runs in the unitBase when i send the unit a command on the client.

you mentioned AI controller, usually that would possess the Unit and then the client would no longer Own the Unit.

For an RTS style game i think it is correct to send Commands from the player controller via RPC

That makes sense in theory, However it doesn’t explain why my test is not firing the server event.

It also complicates defining who can control a unit, it makes sense to set the unit owner to the player who spawns it, and then the authority to control it is just based on that. Feels like what ownership should be for, and can imply a players ownership of an AI too.

Also i am currently using an AI to give move to commands, and they seem to still work despite ownership not changing. I am printing the owner on select and it will return a player controller, not an AI, and that functionality works as expected

Edit: also i am currently using Ownership to define whether the character can be selected, and seems to work fine.

well AI is owned by the server so an AI command is a server command.

In terms of defining you own owner for gameplay/team purposes just create another variable.

It’s been a while since i had this issue so cant be more specific but im pretty sure the problem is basically the AI Possession

You are correct, i disabled AI possession and the server event did fire.

A bit irritating that it wouldn’t alert me to this ownership issue, and return the AI controller as the owner, or break the ai when i took ownership. Seems like a hidden failure in the setting of the ownership.

So yes, it seems like the method is to relay commands to the player controller and then call from the server, which is a bit of a maze, as it just looks like a redundant extra step in the code.

Currently the (working) method to harvest a resource node is :
Right click event on node → PlayerController Client harvest command → PlayerController ServerHarvestCommand-> set blackboard variables on serverside Unit instances and ai takes over

The method i wanted was :
Right click event on node → Unit ServerHarvest → Set blackboard Ai takes over.

It still seems odd that i need two commands on the player controller and cant just immediately call serverHarvest command. Could i be doing something wrong here?

Thanks for solving the original issue.

well you always need a server RPC so that doubles the commands.

the way i do it though is have one Event, SendCommand with an input of GameplayTag, RPC that to server, and then in the unit SwitchOnTag to handle events.

that way one RPC can handle all commands

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