Set Dialogue System text speed/typerwriter effect via functions for all dialogues
-
- Posts: 54
- Joined: Mon Jun 21, 2021 7:48 pm
Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Hey Tony, I feel like I'm 90% on the way to having this typewriter effect working in script by buttons in my option menu but I'm missing something.
Is there a way to have the typewriterEffect for all dialogues/scenes changed from the the main menu scene and persist through all scenes? My Dialogue manager is already persistent and I was attempting to make this change, but it requires a public variable for typewriterEffect.
Currently I'm using overrides to show several dialogues one time for several scenes, and I was using an override for the main menu (just to display "this is the new dialogue speed").
It worked when I used an instance of a small dialogue tester but the dialogue tester persisted into scenes I did not want to have it in.
Is there a way to have the typewriterEffect for all dialogues/scenes changed from the the main menu scene and persist through all scenes? My Dialogue manager is already persistent and I was attempting to make this change, but it requires a public variable for typewriterEffect.
Currently I'm using overrides to show several dialogues one time for several scenes, and I was using an override for the main menu (just to display "this is the new dialogue speed").
It worked when I used an instance of a small dialogue tester but the dialogue tester persisted into scenes I did not want to have it in.
- Attachments
-
- Texxt Speed.PNG (85.73 KiB) Viewed 123244 times
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Hi,
You could try adding an OnConversationStart(Transform) method to your script. In this method, get a reference to the current dialogue UI (which may be a dialogue UI override) and set the speeds on its subtitle panels' typewriter effects. Something like:
You could try adding an OnConversationStart(Transform) method to your script. In this method, get a reference to the current dialogue UI (which may be a dialogue UI override) and set the speeds on its subtitle panels' typewriter effects. Something like:
Code: Select all
private float typewriterSpeed = 90;
private StandardDialogueUI currentUI;
private void OnConversationStart(Transform actor)
{
// When a conversation starts, record the dialogue UI it's using and set its typewriter speeds:
currentUI = DialogueManager.instance.activeConversation.conversationView.dialogueUI as StandardDialogueUI;
SetTypewriterSpeed(typewriterSpeed);
}
private void SetTypewriterSpeed(float speed)
{
typewriterSpeed = speed;
foreach (var subtitlePanel in currentUI.conversationUIElements.subtitlePanels)
{
subtitlePanel.SetTypewriterSpeed(speed);
}
}
public void SetFastSpeed()
{
DialogueManager.displaySettings.subtitleSettings.subtitleCharsPerSecond = 120;
DialogueManager.displaySettings.subtitleSettings.minSubtitleSeconds = 5;
SetTypewriterSpeed(120);
}
//... etc for remaining methods.
-
- Posts: 54
- Joined: Mon Jun 21, 2021 7:48 pm
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Thanks again Tony! That's working on this scene, but I just realized when I select "new game" that I'm using DialogueManager.ResetDatabase to clear the game. Is that the best method for starting a game over with default variables? Or maybe I should be doing them individually instead of a full wipe?
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Hi,
I think that's an unrelated question, correct?
In any case, if you're not using the save system, DialogueManager.ResetDatabase() is the way to reset variables. If you're using the save system, call SaveSystem.ResetGameState() instead.
I think that's an unrelated question, correct?
In any case, if you're not using the save system, DialogueManager.ResetDatabase() is the way to reset variables. If you're using the save system, call SaveSystem.ResetGameState() instead.
-
- Posts: 54
- Joined: Mon Jun 21, 2021 7:48 pm
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
I was thinking that the ResetDatabase() was also clearing the typewriter settings because there wasn't a change on my end but it may be something in one of my other scenes that is causing the issue. I'll check to make sure since I'm doing a bit of refactoring over old mess that I've been putting together.
So for ResetGameState(), will that wipe only the current save? I have been using the save system but just want to make sure.
So for ResetGameState(), will that wipe only the current save? I have been using the save system but just want to make sure.
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
That's correct. SaveSystem.ResetGameState() will only clear the save system's current memory. It won't touch saved game files. To delete a saved game file, use SaveSystem.DeleteSavedGameInSlot(#).
-
- Posts: 54
- Joined: Mon Jun 21, 2021 7:48 pm
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Hey Tony, coming back to this after doing some other work on my project.Tony Li wrote: ↑Fri Jan 05, 2024 10:42 pm Hi,
You could try adding an OnConversationStart(Transform) method to your script. In this method, get a reference to the current dialogue UI (which may be a dialogue UI override) and set the speeds on its subtitle panels' typewriter effects. Something like:
Code: Select all
private float typewriterSpeed = 90; private StandardDialogueUI currentUI; private void OnConversationStart(Transform actor) { // When a conversation starts, record the dialogue UI it's using and set its typewriter speeds: currentUI = DialogueManager.instance.activeConversation.conversationView.dialogueUI as StandardDialogueUI; SetTypewriterSpeed(typewriterSpeed); } private void SetTypewriterSpeed(float speed) { typewriterSpeed = speed; foreach (var subtitlePanel in currentUI.conversationUIElements.subtitlePanels) { subtitlePanel.SetTypewriterSpeed(speed); } } public void SetFastSpeed() { DialogueManager.displaySettings.subtitleSettings.subtitleCharsPerSecond = 120; DialogueManager.displaySettings.subtitleSettings.minSubtitleSeconds = 5; SetTypewriterSpeed(120); } //... etc for remaining methods.
So I used the code above but am getting the following error when not setting a direct "currentUI". It worked when I set it in public to the override but it did not propagate to other scenes.
Code: Select all
NullReferenceException: Object reference not set to an instance of an object
SettingManager.SetTypewriterSpeed (System.Single speed) (at Assets/Scripts/MenuScripts/SettingManager.cs:585)
SettingManager.DialogueSetSlowSpeed () (at Assets/Scripts/MenuScripts/SettingManager.cs:600)
Code: Select all
gameObject.GetComponent();
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Hi,
Is it getting the NullReferenceException in the OnConversationStart() method?
For brevity and readability, my example code omits error checking. In your own code, you'll probably want to check that currentUI isn't null.
Is it getting the NullReferenceException in the OnConversationStart() method?
For brevity and readability, my example code omits error checking. In your own code, you'll probably want to check that currentUI isn't null.
-
- Posts: 54
- Joined: Mon Jun 21, 2021 7:48 pm
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
It seems to be in the SetTypewriterSpeed, but I noticed in the code that OnConversationStart() method is unused
- Attachments
-
- Texxt Speed2.PNG (49.26 KiB) Viewed 122502 times
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
The Dialogue System uses Unity to call OnConversationStart(Transform) through reflection, so to the code editor it may appear as if it won't be used. If you click on the error in the Console window, the bottom of the Console will show the stack trace, which is the order of method calls. In the error, is SetTypewriterSpeed being called from OnConversationStart?
To verify whether it's finding the currentUI, you could change it to:
To verify whether it's finding the currentUI, you could change it to:
Code: Select all
private void OnConversationStart(Transform actor)
{
// When a conversation starts, record the dialogue UI it's using and set its typewriter speeds:
currentUI = DialogueManager.instance.activeConversation.conversationView.dialogueUI as StandardDialogueUI;
if (currentUI == null) Debug.Log("Could not find the dialogue UI to set currentUI.");
SetTypewriterSpeed(typewriterSpeed);
}