Setting Character ownership for an RTS game

Hey all,

I’m trying to determine how to properly set ownership of a character in an RTS game I’m making.

I have it so that I call Set Owner as the owning player controller on the character (a unit). But this still leaves the Net Role of the unit to “Simulated Proxy”, which is the most likely culprit as to why Server-side RPCs aren’t called on the unit class by the player.

Some research states that in order to change the Net Role of the unit, I’ll have to possess it by Player Controller to change the Net Role.

The issue this creates is that I want AI to run on each unit, so its possessed by an AI controller to determine movement behavior and query for enemy units nearby. I’m also not sure if the player controller can possess multiple units either.

Would anyone know a solution to this?

Thanks!

Are you calling SetOwner on the server?

“Owner” is a regular replicated variable, so for it to work correctly, its value needs to be changed on the server.

You should not confuse “Owner” and “Possess”.
Possess - applies to Pawn and Controller only. Controller (Player, or AI) can only Possess one Pawn, and vice versa, a Pawn can only have one Controller.

Owner - applies to any replicated actor (Controllers and Pawns are actors too). This concept refers to network interaction.

Initially, the client only Owns its Player Controller. So initially you can only call Server RPC and receive Client RPC in the Player Controller.
When you Possess a Pawn, you automatically become its Owner, and after that RPC works in Pawn too (but not vice versa, if you made the Controller the Owner of the Pawn - you do not Possess it automatically).

An actor can only have one Owner. But an actor can Own several actors.

Your AI Controllers will Possess units, but the Player Controller (or Player Pawn) can Own all units, and/or all AI Controllers, and thus be able to use RPC on them.