Actor Ownership RTS

Hi,

I’m creating a RTS game and am not sure about the best practice for ownership.

When the player wants to create building he sends it to the server and the server places it and is the owner then.

Now I have to handle inputs for these buildings, for example start/stop production. Therefore I need to send RPCs to the server. But I’m not quite sure what is the best way there. I have 2 ideas for it:

  1. When the servers places the actor, he makes the client owner. The client can then call an RPC from that actor.
  2. I save the buildings in the player state or save them together with the owning player controller and the client sends a request from the player controller to the server where he says like “start production at building X” and the server then checks if the building is in his playerstate and then starts the production.

Hope you can tell me which option is better or have another option which is better.

Thanks in advance!

Hello there! I am currently working on an RTS (more RTT) prototype myself and had to overcome the issue with sending this commands too.

I am actually using a combination of your two suggestions. The owner of my unit actors is set to the clients player state, so I am able to send rpcs directly on the actor to the client.

But the actual commands are handled as in point 2 through the player controller as requests. The main reason behind it is, that because you can select multiple actors (say 10-20) at once, you have to call 10-20 RPCs in order to execute the logic on all actors. If you send the request over the PlayerController, you can pack all commands issued for all actors in only one RPC, safing network traffic.

I also implemented a system, converting all my commands used in the game into a single structure using a combination of GameplayTags as identifiers. Each command is identified by a GameplayTag. It then runs its own execution script on the server to handle actor specific function calls. For example a construction command is send with the GameplayTag Command.Construction and a GameplayTag identifying the class which should be constructed, the target actors of this command (the building) are simply send via their pointer. The server now identifies the matching execution script for the construct command and the script will cast the target actors to the building type and execute the needed functions.

And also because the actors owner is the PlayerState and my PlayerState is assigned to a team, I can check to which player this actor belongs and in which team the player is. And because I use the PlayerState, every client can make this checks (useful for visibility updates which must be done for each client locally). Hope this helps a little.

Yeah, definetely helped. Thanks a lot.

But one question: Do you store the buildings and units in playerstate or in gamestate

Good to hear that it helped :).

I store these in PlayerState for better separation what belongs to whom. (In GameState I store units/buildings not belonging to anyone, team neutral so to say).

But you dont need this storage necessarily (I just using it for Win/Loose condition checks and statistics), because you can simply check the unit owner (which is PlayerState) to whom this unit belongs most of the time.

Ok, was planning to do it like that, good to have proof. Thanks for the help!