How can I pause a game running on a dedicated server?

I’m working on developing a training simulator, and would like for the simulation to pause at various points so that the trainees can answer questions related to what they’re doing.

The single-player prototype worked without a hitch, but the project I’m working on is a multiplayer game hosted on a dedicated server. So far, every attempt to pause the game has failed.

#Blueprint Code

Here’s the relevant blueprint code in my PlayerController:

I created “TEST_ClientRequestPause” and tied it to a button press so that I could test easier. It makes an RPC call to the server-side method (which would normally be triggered by an event on the server). The server-side event then calls other RPCs to attempt to pause the game. I’ve tried:

  • Server-side only
  • Client-side only
  • Multicast

The image above shows calls to the client-only and multicast RPCs.

#Client Log

[2019.01.08-16.31.27:064][470]Strm: Error: Client request pause

[2019.01.08-16.31.27:096][472]Strm: Error: Invoking multicast pause

[2019.01.08-16.31.27:097][472]Strm: Error: Multicast pause success: false

[2019.01.08-16.31.27:097][472]Strm: Error: Invoking client pause

[2019.01.08-16.31.27:098][472]Strm: Error: Client pause success: false

#Server Log

[2019.01.08-16.31.27:076][296]Strm: Error: Server request

[2019.01.08-16.31.27:077][296]Strm: Error: GameMode can pause: true

[2019.01.08-16.31.27:077][296]Strm: Error: Invoking multicast

[2019.01.08-16.31.27:078][296]Strm: Error: Multicast pause success: false

#Analysis

The RPCs seem to be functioning as expected (the events are in the expected order and in the expected logs).
The GameMode is reporting that it can pause. Perhaps network pausing is limited somewhere else (this post seems to indicate that network pausing is disabled by default).
The log indicates that immediately after invoking “SetGamePaused(true),” the “IsGamePaused” node is returning false. I’ve also connected the boolean output of the “SetGamePaused” node to my log statement - it also returns false in all cases.

If anyone has any insight on why that might be the case, I would love to hear it. Is there an option somewhere in the project that needs to be set? Do I need to manage my RPCs differently? Answer #6 from vipeout in this post seems to suggest that the clients need to pause before the server pauses, but I can’t seem to get the clients to pause (and I’m less concerned with preserving the “pauser” in the world state). Is there a known issue that would prevent a dedicated server from pausing? Are there any common mistakes that might cause the “SetGamePaused” node to return false?

Thanks!

It’s been a week - time for a little bump to get this thing back into circulation. If nothing else, it’ll indicate that I’m still interested in this conundrum!

Evidently, the multicast RPC in the PlayerController was a mistake - PlayerController exists only on the server and on the owning client, so the multicast breaks down as soon as there’s a second client involved.

Unfortunately, the game still doesn’t pause when using the client RPC. Still looking for ideas about why that might be the case!

Is this what you are looking for?

https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/105624-multiplayer-pause

Hey xXZUKINIXx!

I did run into that forum post while I was searching for an answer, before I posted this question. Actually, I even linked it in my question (in the analysis section) because vipeout’s answer seemed like it might be highlighting some pitfalls that you can fall into (namely, pausing the server before pausing the clients).

Unfortunately, I think my code is remarkably similar to what’s being done in that post, and I’m still not successfully pausing. I omitted the calls to disable user input and stop movement in my example, but I assume those aren’t prerequisites for pausing the game.

Thanks for the comment though - it’s nice to have someone other than myself here :wink:

Sorry I missed that :frowning:

If I catch anything else I will let you know!

No worries! I wasn’t trying to reprimand you for it, I was just clarifying what I’d seen so far!
Thanks again :slight_smile:

Alright, it’s been a couple of weeks - let’s give this another bump back into circulation.

Still looking for any pitfalls that might explain why the pause functionality might misbehave!

Would like an answer too, same issue.

@Bryant_PSC I’ve noticed that the Server will pause and the clients wont appear to, but my characters will go back to where they were before pausing. Have you noticed this?

If you want the game world itself to pause with the player instead of just pulling up a “pause” menu try having the level blueprint itself activate the pause node inside of itself or alternatively you can use the level bp to force every other players to press the button whenever one of them presses it

This doesn’t solve the issue. The Server will pause, and the clients sometimes will pause, and other times continue running or appear to be running.

https://files.ashlandce.com//UE4Editor_2019-02-14_00-09-53.png

Hey @SkySaberStudios!

Could I trouble you for some clarification?
The code which is going to trip the pause functionality lives outside of the level blueprint (currently, it resides in the PlayerController and GameMode). If I put the pause functionality in the level blueprint, how should I call it?

  • Should I RPC to the server, then call the function in the level blueprint?
  • Should I RPC to the server, then use a series of “run on owning client” RPCs that make calls the level blueprint?

I don’t use the level blueprint all that often because I have a bunch of levels that need to exhibit similar behavior. Does the level blueprint support replication? Haha, I found out the hard way that not all classes do

I don’t think my server is successfully pausing, but I’ll try to keep an eye on that if I get a chance to tinker with it later today.
Are you using the technique outlined here? https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/105624-multiplayer-pause?p=1419389#post1419389
I’ve been trying to get the clients to pause before telling the server to pause, but so far my “SetGamePaused” node has returned false every time.

How similar is your code to the BPs I posted above?

The level blueprint can look for and cast to all actors of a specific class or parent class in a level, if you link the pause event in the player class to a custom event you can call that event from the level blueprint, by using this and aplying it client side you could possibly mass pause the clients that are inside that map, however please take this suggestion with a grain of salt as I both cannot check my idea nor can I implement it since at the moment as im still wrapping my head around networking at all

Alright, so I played around with this a bit, and I get the same results that I do by attempting to pause the game from the GameMode. In particular, the SetGamePaused node indicates that it failed and the game keeps playing.

Here’s a little more detail about what I tried:

In all cases, I’m using an Event Dispatcher bound to the Character that I’m controlling. There doesn’t seem to be an easy way to get a reference to the Level Blueprint at runtime, so I call a Bind Event in the Level Blueprint’s Begin Play event (after a short delay to give my Characters a chance to spawn). The event binding appears to be working as expected - the Character can use the bound events to make things happen in the Level Blueprint.

Some of the tests that I performed:

  • Call the SetGamePaused node locally (no RPC)
  • Call an event in the Level Blueprint which performs an RPC to the server (this failed because the Level Blueprint had no owning connection - the server RPC never fired)
  • Call a server RPC in the Character which runs the SetGamePaused node in the Level Blueprint
  • Call a server RPC in the Character which runs SetGamePaused in the LevelBlueprint followed by looping through all of the connected players and calling a client-side RPC to attempt to pause them. Interestingly, the client-side RPC did reach the clients as expected (suggesting that the Player Controller’s owning connection is used here instead of the Level BP’s owning connection)
  • The same as the previous attempt, but with a second call to SetGamePaused on the server after running the client RPCs and delaying for a second. This was a hedge against the theory that the clients need to pause first

Oh, and with regard to wrapping your head around networking - I completely understand haha. UE4’s network setup is a little hard to comprehend. My advice would be to use lots of logging, so that you can see whether something is occurring on the server or the client. I’ve definitely had several occasions that I’ve seen a message appear in the server log when I expected it in the client (or vice versa), and it at least tells you that you need to investigate the related RPCs.

Hey @LaneRendell!

An update on what I’ve been seeing - neither client nor server reports that it successfully pauses the game.
Since it’s a dedicated server, I can’t see what’s happening with my character there. However, I assume that it’s not pausing on the server either, because my character continues moving unimpeded (and it does have replicated movement, so it should be matching the dedicated server’s position).

tl;dr - I think you’re closer to pausing than I am. I haven’t noticed my characters returning to the location they should have been at when the game paused.

Did you try having the level blueprint look for the keypress rather than the pawn? Also sorry that I cant help you more by trouble shooting with you on my owncmachine im at work rn, once im done with work (about 5 and 3 quarters of a hour from when I post) I could start adding a network to my own project and try helping you

I did not even consider that possibility when I tried it yesterday haha - like I said, I haven’t played with Level Blueprints too much.

I tried this morning, though, and didn’t meet with success. I was only able to perform client-side actions from the Level Blueprint (any server RPCs failed because the Level Blueprint didn’t have an owning connection).

It was worth a shot, but I suspect that putting the pause code into the Level Blueprint isn’t the key here. One clue that leads me to believe that the Level BP isn’t necessary is that I was able to pause a single-player game by putting the SetGamePaused node in the Player Controller. Maybe there’s something about a dedicated server that makes it necessary to pause from a specific blueprint, but my gut tells me that the issue is something else. Maybe an option that I’ve missed somewhere in my setup, or some trick that needs to be done with the right combination of RPCs.

Here’s what I had in my Level BP:

Like I said, the “ServerPause” failed because the Level BP didn’t have an owning connection. The PlayerControllerPause failed because the game mode doesn’t exist on the client (GetStrmGameMode just gets and casts my game mode). I’m pretty confident that the MulticastPause ran on the client only, and both that and the ClientPause yielded false for both of the printed Booleans.