top of page

Fixing Attack Replication Issues

  • Writer: Roland Thomas
    Roland Thomas
  • Dec 6, 2023
  • 2 min read

I encountered two major problem with replication. The first was that the animation for the 3-hit basic attack combo when initiated on the server would not be seen on the client.


Secondly, a strange thing would happen where both in-game characters would perform hitbox checks when the a player performs a basic attack. If a character was standing in the range of the server when the client dealt an attack, it would be as if both characters were dealing damage. This was especially odd to me, because the box collision component used to detect melee attacks was set to not replicate across the network.


The Animation Issue

In order to fix the animation issue, I looked at the logic again. In order to have the animations sync on the client without lag, the animation is played locally, and then an RPC plays the animation on the server. The problem with this method was that it didn't take into account what happens if the Server initiates the animation, because at no point in the logic does it replicate to the client.

The existing RPC logic for playing Basic Attack Animations

The first solution I came up with to solve this was to have the server multicast the animation if it's the one initiation the basic attack, and the use the existing logic if it's the client. This way the initiating client still sees the animations locally without any lag, and the initiating server multicasts it, so the animation is replicated to both players.

The revised solution for playing Basic Attack animations
Revised Basic Attack animation RPCs. Now one for the server and a multicast one

I clearly focused on making sure the client replication worked when I initially design the process, however this bug taught me that I should consider and test both sides of the replication when building a feature, to ensure I get the expected behaviour.



The Hitbox Issue

To debug the second problem I printed debug messages at important stages of the damage dealing process, and discovered that when the server would attack a character, the OnComponentHit event on the client's character would still activate, dealing damage if an enemy was in front of them.


Upon investigation I discovered that the events to turn the melee hitbox on and off were not set to replicate. This meant that whenever either of the players did the basic attack animation (if the animation is replicated), it would toggle the hitbox for both players. I consider this to be an easy mistake to miss, as the functions are are initiated by AnimNotifies during the attack animation, so I wouldn't normally think about replication for them. This showed me that while not everything needs to replicated, all features in a multiplayer game must at least be considered for it to avoid further oversights like this.


Damage dealing is an important feature of the game that should be kept server-authoritative to prevent cheating, so to solve this turned the melee hitbox toggle events into Server RPCs. This way, only the server's version of each character would initiate the damage process, ensuring that it only happens once.


Activate/Deactivate hitbox events are now Server RPCs
Client-side view of damage process checks only happening once, on the server




Recent Posts

See All
TODO: Session UI & Pause Screen

Started Session UI. Created most of the widgets, just need to complete the Find Session one, then include the functionality. Also created...

 
 
 

Comments


© 2024 by Rolandson Thomas. 

bottom of page