Should i call Server functions on the server?

Hello, i have a Server function called ServerSomething that runs a certain logic and i have the TakeDamage function, which is also executed on the server. There is a specific case in TakeDamage that i want to execute the logic on ServerSomething. Should i move the entire ServerSomething logic to a new method called DoSomething which is called by both ServerSomething and TakeDamage or it’s fine to just run ServerSomething? Does this also apply to Client functions running on the client? Thank you

Thank you for your answer :slight_smile:

Thanks :slight_smile: I was just asking for performance reasons because the Server functions calls adds a little bit of overhead.

You certainly can but it is not recommended, not that it will fail but it might be confusing. IN such cases where the server function has some logic that is exactly the same to be reused somewhere else I normally call use the following function names:

  • ClientDoSomething → Calls DoSomething on the client
  • ServerDoSomething → Calls DoSomething on the server
  • DoSomething → :smiley: I guess we know what that one does :smiley:

The same applies to the client where I would better a DoSomething like this:

void ClientDoSomething() {

The good thing using this is that you can call DoSomething on the client (within a client function), in variable replication notification (RepNotify) and the server function. So you call the same code in every place, which results in cleaner code and less bugs.

Another nice way is to have two functions like:

  • DoSomething → Abstraction layer for DoSomething
  • DoSomethingWorker → Does the actual work

Hope this helps a bit, using the same name paradigm gives you a clean code base and in replication code this is a must to not get lost in the middle.



Just an update for anyone reading this in the future: in 4.14 calling a server ufunction on the server will not actually execute it. If you want to be able to call a function from the server you’ll need to do something like this (see shooter sample):

void Myfunction()
      if(Role != ROLE_Authority) 
      /* function logic goes here*/

void Server_Myfunction_Implementation()