Somthing thats only on the server?

If I want to have a timer that is only run on the server.
Is the correct way of doing it to, create a timer in the GameMode class and give the value updated / replicated in GameState? So Players and Server always have the same value?

Or is it a other way of defining something that’s only existent server or client side?

You can simply start the timer on the server using a server function to start the process!

Since the server function is the one calling the timer, it will only ever run on the server.

To avoid telling the timer to start multiple times, with included internet lag making the results go off a bit, (calling the timer multiple times will restart it), make sure to only call the server function while on the Server (HasAuthority())

See below!


#.h

    UFUNCTION()
    void TheActualTimerFunction();
    
    UFUNCTION(Reliable, Server, WithValidation)
    void SERVER_StartTimerFunction();

#.CPP

    void AVictoryGamePlayerController::SERVER_StartTimerFunction_Validate()
    {
      return true;
    }
    void AVictoryGamePlayerController::SERVER_StartTimerFunction_Implementation()
    {
       //start the timer
       GetWorldTimerManager().SetTimer(this, 
    		&AVictoryGamePlayerController::TheActualTimerFunction, 
    			0.03, true); //looping
    }


    //somewheres in your code
        if(HasAuthority())
        {
          SERVER_StartTimerFunction();
        }

#Even Simpler

The above is if you are over-precautious about making sure only the server ever runs the function

if you have confidence you will always check HasAuthority()

**all you need is this:**

    //somewheres in your code
            if(HasAuthority())
            {
               //start the timer
           GetWorldTimerManager().SetTimer(this, 
        		&AVictoryGamePlayerController::TheActualTimerFunction, 
        			0.03, true); //looping
            }


The above timer call will only run on the server

Thank you for that great explination.