How to pause a game during a dialogue?
Re: How to pause a game during a dialogue?
Still problems. I've sent my project along with the detailed description to your email.
Re: How to pause a game during a dialogue?
Hi,
Sorry, it was indeed a bug. I sent you the updated Unity UI Support package via email.
The dialogue UI used to cache Time.timeScale right before it started the "Show" animation. This was so it could temporarily set timeScale to 1 to play animations on animators that were set to Normal update mode. (In Normal update mode, animations are scaled according to timeScale. If timeScale were 0 in this case, the animation would never run.) At the end of the animation, it restored the cached timeScale.
In your case, the dialogue UI caches timeScale==1. Then it started the animation, and on the same frame your Management script set timeScale=0. Finally, when the animation was done, the dialogue UI restored timeScale to the cached value (1).
The dialogue UI code was later changed to simply reporting a warning if the game is paused and the animator uses Normal update mode. However, it still restored the cached value.
In the updated package, it no longer restored the cached value.
Sorry, it was indeed a bug. I sent you the updated Unity UI Support package via email.
The dialogue UI used to cache Time.timeScale right before it started the "Show" animation. This was so it could temporarily set timeScale to 1 to play animations on animators that were set to Normal update mode. (In Normal update mode, animations are scaled according to timeScale. If timeScale were 0 in this case, the animation would never run.) At the end of the animation, it restored the cached timeScale.
In your case, the dialogue UI caches timeScale==1. Then it started the animation, and on the same frame your Management script set timeScale=0. Finally, when the animation was done, the dialogue UI restored timeScale to the cached value (1).
The dialogue UI code was later changed to simply reporting a warning if the game is paused and the animator uses Normal update mode. However, it still restored the cached value.
In the updated package, it no longer restored the cached value.
Re: How to pause a game during a dialogue?
Yep. It's fixed. Hooray!
Thanks
Thanks
Re: How to pause a game during a dialogue?
Thanks for your patience on this one. Sorry about the bug! I'm glad it's fixed now.
Re: How to pause a game during a dialogue?
Hello, can you tell me where to add that custom Boolean field? Not sure how to add that to conversations and/or add a script to an individual conversation. Thanks!
Tony Li wrote: ↑Mon Dec 12, 2016 4:18 pmIf I understand you correctly, here's a way that uses a small script:Ondatr wrote:What is the correct way to pause regular gameplay during dialogues excluding given list of dialogues?
1. Add a custom Boolean field to your conversations named something like "PauseGameplay". In conversations that should pause gameplay, set the field to True.
(Side note: If you add this to your Conversation template on the Templates tab, tick the Main checkbox to auto-add it to each conversation and make it appear in the main editor part so you don't have to expand the All Fields foldout.)
2. Add to the Dialogue Manager a small script that checks this field and pauses/unpauses the game if appropriate:
Code: Select all
using UnityEngine; using PixelCrushers.DialogueSystem; public class PauseGameplayDuringConversations : MonoBehaviour { bool ShouldCurrentConversationPause() { var id = DialogueManager.CurrentConversationState.subtitle.dialogueEntry.conversationID; return Lua.IsTrue("Conversation[" + id + "].PauseGameplay"); } void OnConversationStart(Transform actor) { if (ShouldCurrentConversationPause()) { /* pause */ } } void OnConversationEnd(Transform actor) { if (ShouldCurrentConversationPause()) { /* unpause */ } } }
Re: How to pause a game during a dialogue?
Hi,
You can add the Boolean field to your template:
Then select Menu > Apply Template To Assets to add the new field to your existing conversations.
If you tick the checkbox in the Main column, your new field will be visible in the main part of the inspector. Otherwise it will only be visible in the All Fields section:
Then you can write a script (or use a PlayMaker FSM, etc.) to check the field when a conversation starts and ends. For example, add a script like this to your Dialogue Manager or your player GameObject. If you add it to the Dialogue Manager, every conversation will trigger this script, which checks the Boolean field and possibly pauses the game. If you add it to the player GameObject, only conversations involving the player as one of the two main participants will trigger it.
CheckPausableConversation.cs
You can add the Boolean field to your template:
Then select Menu > Apply Template To Assets to add the new field to your existing conversations.
If you tick the checkbox in the Main column, your new field will be visible in the main part of the inspector. Otherwise it will only be visible in the All Fields section:
Then you can write a script (or use a PlayMaker FSM, etc.) to check the field when a conversation starts and ends. For example, add a script like this to your Dialogue Manager or your player GameObject. If you add it to the Dialogue Manager, every conversation will trigger this script, which checks the Boolean field and possibly pauses the game. If you add it to the player GameObject, only conversations involving the player as one of the two main participants will trigger it.
CheckPausableConversation.cs
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class CheckPausableConversation : MonoBehaviour
{
void OnConversationStart(Transform actor)
{
if (isPauseGameplayTrue()) Time.timeScale = 0;
}
void OnConversationEnd(Transform actor)
{
Time.timeScale = 1;
}
bool isPauseGameplayTrue()
{
var conversation = DialogueManager.MasterDatabase.GetConversation(DialogueManager.LastConversationStarted);
return (conversation != null) && conversation.LookupBool("PauseGameplay");
}
}
Re: How to pause a game during a dialogue?
Thanks for such a great reply Tony! Using your scripts and instructions I was able to get the game to pause nicely, thank you!!
Re: How to pause a game during a dialogue?
Happy to help!