Page 1 of 2
Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Posted: Fri Jan 05, 2024 8:33 pm
by xyztankman
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.
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Posted: Fri Jan 05, 2024 10:42 pm
by Tony Li
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.
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Posted: Sat Jan 06, 2024 1:33 am
by xyztankman
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
Posted: Sat Jan 06, 2024 9:26 am
by Tony Li
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.
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Posted: Sat Jan 06, 2024 2:46 pm
by xyztankman
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.
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Posted: Sat Jan 06, 2024 3:08 pm
by Tony Li
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(#).
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Posted: Wed Jan 10, 2024 9:39 am
by xyztankman
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.
Hey Tony, coming back to this after doing some other work on my project.
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)
Should I be using something like
to find the currentUI?
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Posted: Wed Jan 10, 2024 10:29 am
by Tony Li
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.
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Posted: Wed Jan 10, 2024 12:04 pm
by xyztankman
Tony Li wrote: ↑Wed Jan 10, 2024 10:29 am
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.
It seems to be in the SetTypewriterSpeed, but I noticed in the code that OnConversationStart() method is unused
Re: Set Dialogue System text speed/typerwriter effect via functions for all dialogues
Posted: Wed Jan 10, 2024 12:56 pm
by Tony Li
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:
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);
}