Tony Li wrote: ↑Wed Jan 10, 2024 12:56 pm
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:
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);
}
Full stack trace below, no debug message when clicked. I separated minSubtitleSeconds and made it a separate function, oddly there is no error message and the changed seconds works:
I only get the error when SetTypewriterSpeed is listed
Yes I was calling DialogueSetSlowSpeed() without a conversation active, I was using it as a button to start a conversation to show the new speed. Here's a screenshot of the button setup. DialogueTest is the override.
TextSpeed_Button.PNG (64.33 KiB) Viewed 123918 times
No longer an error message, but the speed of the text doesn't seem to be updating for the buttons. Gif linked below as well
This way you can see its value in the inspector. Then play the scene and keep the GameObject with this script selected so you can watch the value. When you click the button, does typewriterSpeed change?
If so, then the OnConversationStart() method should update the typewriter speeds of all subtitle panels assigned to the current dialogue UI's Subtitle Panels list. (Remember from my earlier post that it doesn't touch other subtitle panels, such as if a Dialogue Actor points to a bubble subtitle panel. You'll need to extend the script further if you need to do that.)
This way you can see its value in the inspector. Then play the scene and keep the GameObject with this script selected so you can watch the value. When you click the button, does typewriterSpeed change?
If so, then the OnConversationStart() method should update the typewriter speeds of all subtitle panels assigned to the current dialogue UI's Subtitle Panels list. (Remember from my earlier post that it doesn't touch other subtitle panels, such as if a Dialogue Actor points to a bubble subtitle panel. You'll need to extend the script further if you need to do that.)
Confirmed that the TypewriterSpeed is changing correctly when shown in [SerializeField], although still not seeing a change in the actual dialogue. Could this be a problem with my UI prefab? I removed the PC and response menus as there is only an NPC dialogue that plays.
DialogueTestPrefab.PNG (89.81 KiB) Viewed 123900 times
Your script is on the Dialogue Manager GameObject, correct? (I believe I mentioned that, but just checking in case you missed it.) It will only run OnConversationStart if it's on the Dialogue Manager or one of the participants.
If you don't want the script to be on the Dialogue Manager, you can use the DialogueManager.instance.conversationStarted C# event instead. Here's an example scene:
Your script is on the Dialogue Manager GameObject, correct? (I believe I mentioned that, but just checking in case you missed it.) It will only run OnConversationStart if it's on the Dialogue Manager or one of the participants.
If you don't want the script to be on the Dialogue Manager, you can use the DialogueManager.instance.conversationStarted C# event instead. Here's an example scene:
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class TypewriterSpeedManager : MonoBehaviour
{
[SerializeField] private float typewriterSpeed = 90;
private StandardDialogueUI currentUI;
private void Start()
{
DialogueManager.instance.conversationStarted += OnConversationStarted;
}
private void OnDestroy()
{
DialogueManager.instance.conversationStarted -= OnConversationStarted;
}
private void OnConversationStarted(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;
if (currentUI != null)
{
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);
}
public void SetNormalSpeed()
{
DialogueManager.displaySettings.subtitleSettings.subtitleCharsPerSecond = 90;
DialogueManager.displaySettings.subtitleSettings.minSubtitleSeconds = 5;
SetTypewriterSpeed(90);
}
public void SetSlowSpeed()
{
DialogueManager.displaySettings.subtitleSettings.subtitleCharsPerSecond = 20;
DialogueManager.displaySettings.subtitleSettings.minSubtitleSeconds = 5;
SetTypewriterSpeed(20);
}
}
ok now we're in business! I did have it on my own SettingsManager script but after moving it to the DialogueSystemController script it is working! Confirmed after changing scenes.
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.
Yes I was thinking that too, I did switch to the ResetGameState() and that seems to be working so far along with having the script directly on the dialogue manager.