No announcement yet.

Do a function on the server from a client

  • Filter
  • Time
  • Show
Clear All
new posts

    Do a function on the server from a client

    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.

    I'm trying to make a multiplayer game where players can push the ball by pressing a key (Here it's "T"), I want the ball to be in the same place for all player so it is replicated on all clients.
    So the ball is in the same place for all player when I juste use physics on it, but when I try to use my function "Push" it works only for the host but not for the client.
    I tried to make my function being multicasted but then the client will only do the function on his client and not on the server.
    So I tried to make it being On Server but then when I use it on my client it just does nothing (I think it was supposed to do it on the server as this page says :
    Run on Owning client doesn't work too.

    Does someone knows a way to make the client execute this function on the server?

    (I'm a total newbie on unreal so my blueprint is probably filled with errors and redundancy, please forgive me.)
    (And don't mind the prints they are just here for debugging.)
    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.
    Click image for larger version

Name:	PlayerControllerClientToServerPush.PNG
Views:	214
Size:	167.2 KB
ID:	1462478
    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.


      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.