Player Attack Animations over the Network


Author: Adam Stagg

The challenge for this week was to get the player attacks working over the network. I was having some issues with the RPCs not working in the correct way, and I am still unsure why it was not working. I switched from working on my desktop to my laptop, rewrote the exact same code, and it worked. Regardless, it is working now, and the light and heavy attacks are able to be seen across every player.

When the attack is called, it goes to a server RPC, which then calls a multicast RPC. Multicast RPCs will execute on every client and server when called on the server, but only on the client if called by a client. This will ensure that every single client and the server all will get the same call to the attack. 
The general structure for this goes:

.h
UFUNCTION(Server)
void ServerFunction();

UFUNCTION(NetMulticast)
void MulticastFunction();

.cpp

void ServerFunction()
{
    //Any server specific code

    MulticastFunction();
}

void MulticastFunction()
{
    //Code to be executed on every player
}

Leave a comment

Log in with itch.io to leave a comment.