[HELP][PUN 2] Not Receiving RPC requests when Time.timeScale set to 0
Options
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) allPaused = false;
Time.timeScale = (allPaused) ? 0f : 1f;
AudioManager.instance.TogglePauseAllAudio(allPaused);
}
Comments:
- 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();
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!
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) allPaused = false;
Time.timeScale = (allPaused) ? 0f : 1f;
AudioManager.instance.TogglePauseAllAudio(allPaused);
}
Comments:
- 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();
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!
0
Comments
-
Has anyone figured out any alternatives? Still dealing with this issue0
-
if (!PauseList) allPaused = false;
This looks suspicious. Shouldn't it be PauseList?
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: developer@photonengine.com0 -
if (!PauseList) allPaused = false;
This looks suspicious. Shouldn't it be PauseList?
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: developer@photonengine.com
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:public 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 everyone is 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); }
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!0 -
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.0 -
Hi @forgemaster,
Thank you for choosing Photon!
Did you read this?
Did you tryPhotonNetwork.MinimalTimeScaleToDispatchInFixedUpdate = 0;
1 -
Hi @forgemaster,
Thank you for choosing Photon!
Did you read this?
Did you tryPhotonNetwork.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!0