The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

[HELP][PUN 2] Not Receiving RPC requests when Time.timeScale set to 0

forgemaster
2020-03-03 22:08:02

Hello All :)

What I am trying to do:
I am trying to make it so that if everyone in the room is "paused" (pressed the escape key) that the game freezes (timeScale = 0) and when 1 person unpauses on there end it unfreezes the game for everyone. Meaning if only 1 person is in the pause menu the game should still resume, only if everyone is in the pause menu that we freeze the game.

The problem:
The problem is once everyone becomes frozen and when 1 person unpauses only that person resumes the game where as everyone else is still frozen.

Code:
private void TogglePauseMenu() {
Debug.Log("Pressed ESC Key");
isGamePaused = !isGamePaused;
PauseMenu.SetActive(isGamePaused);
photonView.RPC("UpdatePauseStatus", RpcTarget.All, PhotonRoom.GetMyNumberInRoom() - 1, isGamePaused);
}

[ PunRPC ]
private void UpdatePauseStatus(int id, bool isPaused) {
Debug.Log("Updating Pause Status");
PauseList[id] = isPaused;
// check if all players paused
bool allPaused = true;
for (int i = 0; i < PauseList.Length; i++)
if (!PauseList[i]) allPaused = false;
Time.timeScale = (allPaused) ? 0f : 1f;
AudioManager.instance.TogglePauseAllAudio(allPaused);
}

Comments:
[color=#ababab]- I've tried looking everywhere online regarding this situation but still haven't found a solution.

  • On the API documentation it claims that MinimalTimeScaleToDispatchInFixedUpdate will ignore timeScale by default, so I thought maybe since my check
    if (Input.GetKeyDown(KeyCode.Escape))
    TogglePauseMenu();

    [color=#ababab]was in the Update method that that would be the issue but I tried putting it in FixedUpdate and LateUpdate and the problem still persisted.

  • One possible solution I found was that I should set the Time.timeScale to something small like 0.01 but the thing is that it doesn't fully pause the game things the background still move really slowly. If I set it to something like 0.0001 then it's the same as if I set it to 0.

So basically is there a way to sync Time.timeScale accross the network?
Thanks for taking the time to help, I greatly appreciate it! :)
[/color]

Comments

forgemaster
2020-03-07 04:11:23

Has anyone figured out any alternatives? Still dealing with this issue :(

Tobias
2020-03-09 15:35:58

This looks suspicious. Shouldn't it be PauseList[i]?
If that doesn't help, create a small repro case and send it (without assets).
Upload to dropbox or such and mail the download link to: [email protected]

forgemaster
2020-03-10 05:21:15

@Tobias wrote: »

if (!PauseList) allPaused = false;

This looks suspicious. Shouldn't it be PauseList[i]?
If that doesn't help, create a small repro case and send it (without assets).
Upload to dropbox or such and mail the download link to: [email protected]

Oops seems like the formatting of my original post didn't include the square bracket I had in my code for accessing the array. Not sure if I can edit the OP but here is the code using code format:

So this shouldn't be the problem since the code logic is just checking if at least 1 person is not paused then allPaused = false. (I assume everyone is paused before the for-loop by setting allPaused = true and then we update the bool if we find that 1 person isn't paused)

Another reason this isn't it is because the Debug.Log("Updating Pause Status"); never outputs when everyone is paused and 1 person sends an unpause request. So it never even reaches to that point to begin with.

I will try to recreate this issue in an empty project tomorrow and send it to the email you provided.

Anyway, thanks for the help!

Tobias
2020-03-10 09:59:10

Yes, please try to do a minimal repro case.

There is also another thread in this forum, which is about RPCs and TimeScale. I lost track of it but a search should help. I think there was a solution.

JohnTube
2020-03-17 11:51:46

Hi @forgemaster,

Thank you for choosing Photon!

Did you read this?
Did you try

forgemaster
2020-03-22 09:41:15

@JohnTube wrote: »

Hi @forgemaster,

Thank you for choosing Photon!

Did you read this?
Did you try

PhotonNetwork.MinimalTimeScaleToDispatchInFixedUpdate = 0;

Oh I must have misread the docs regarding MinimalTimeScaleToDispatchInFixedUpdate, I thought it had to be set to -1 for PUN to recieve RPCs. :#

Thank you so much, I set the value to 0 and it worked! Cheers! :)

Back to top