Download

Optimal Way to Replicate Player Attributes & Scores that Persist Through Disconnects [GAS]

I have the Gameplay Ability System (GAS) implemented in my project, and now I’m trying to think through how I can set up scores, stats, & attributes to replicate in a way that persists through player disconnects.

Here are a few of the places I thought about putting this replicated data:

  • In the ability system component: Won’t work. I already have the attribute component’s attributes replicating (ability system component on the pawn), which is necessary for GAS to work properly, but that is not sufficient because if a player disconnects that pawn is destroyed and the data goes with it.

  • **In the player state: **Won’t work. Player state goes away on player disconnect.

  • In the game state: Could work, but far from optimal. Reading the description of game state this sounds like a great fit as it persists after player disconnect. The problem is there is only one game state and any number of players. This means the replicated variables would have to be arrays. This means each time any value in the array changes, the ENTIRE array is sent to EVERYONE on the network. Yuck. Even if I designed it around this issue to minimize data in each array by making a separate array for each individual stat/score, that is still a lot network traffic for no reason. Consider a “damage score”, with 8 players in the game, each time a player does any damage the full array of all 8 players’ damage scores is sent over the network even though only one element in the array changed.

Will this work?

So, I’m thinking I’ll create a replicated actor called “scores”, and it will contain individual replicated variables for everything that needs to persist (attributes/scores/stats). When the game starts one of these will be spawned by the server and placed in the world for each player, and used to replicate that player’s data. That way if a player leaves, their “scores” actor persists, and if that player rejoins they can be reconnected with their “scores” actor which will be there waiting for them. Downsides include: it’s a bit annoying to manage, and GAS attributes are replicated twice. Is this a bad idea? Is there a better way?

Any way to avoid having to replicate GAS attributes twice without moving the ability system component off of the pawn?

I received the below advice via the unreal slackers discord, based on that I will try moving the ASC to the player state, as well as player scores/stats, and try to preserve that data through player disconnects …hopefully it works!