Do a function on the server from a client

Hi,
I repost this topic because I accidentally supressed the last one.
So this topic is about executing a function on a server from a client.
In my case I want a client to apply an impulse on a ball.

To the nice person who was helping me could you repost your solution? I was working on it, really sorry.

No worries here it is!

First of all you need to remember that replication ONLY happens from server to client.

The ball I assume you have set to “Replicates” and “Replicate movement”, then you have to apply the force server-side and the “Replicate movement” takes care of replicating the movement to the clients.

In order for a client to send a RPC to the server (“Run On Server” Event) the client needs to own the actor it is sending from. It could be the PlayerController or Pawn.

In this example I am Using the PlayerController.


The Reason that there is 2 RPC’s (SERVER_PushBegin and SERVER_PushEnd) is because you never want to spam RPC’s over the network but only the required ones when something changes.

2 Likes

The problem was as you said that I made my blueprint in the ball and not in the pawn, I had to make some modifications to adapt it to the pawn but it is now perfectly working.
Thank you very much for your help !

You’re welcome.