fix: dialogue system race condition + null safety

- CampaignManager: subscribe OnDialogueComplete BEFORE StartDialogue
  (prevents game getting stuck in Dialogue state when dialogue not found)
- DialogueUI: null checks for _dialoguePanel, _continueIndicator,
  _speakerNameText, _speakerPortrait, _continueIndicator in coroutines
- DialogueUI: fix Update fallback — check action != null before skipping
  keyboard/mouse input
This commit is contained in:
2026-08-17 21:48:04 -03:00
parent bf3bec3bb3
commit 072537211c
5 changed files with 20380 additions and 3480 deletions
@@ -359,19 +359,22 @@ public class CampaignManager : MonoBehaviour
{
Debug.Log($"[CampaignManager] Diálogo intro: {chapter.introDialogueId}");
if (GameStateManager.Instance != null)
GameStateManager.Instance.TransitionTo(GameState.Dialogue);
if (DialogueSystem.Instance != null)
{
DialogueSystem.Instance.StartDialogue(chapter.introDialogueId);
// Subscribe BEFORE starting — StartDialogue can fire OnDialogueComplete immediately
// if dialogue is not found, which would skip the transition.
DialogueSystem.Instance.OnDialogueComplete += OnIntroDialogueComplete;
DialogueSystem.Instance.StartDialogue(chapter.introDialogueId);
}
else
{
Debug.LogWarning("[CampaignManager] DialogueSystem no disponible. Saltando intro.");
TransitionToPlaying();
return;
}
if (GameStateManager.Instance != null)
GameStateManager.Instance.TransitionTo(GameState.Dialogue);
}
private void OnIntroDialogueComplete()
@@ -396,19 +399,21 @@ public class CampaignManager : MonoBehaviour
Debug.Log($"[CampaignManager] Diálogo outro: {CurrentChapter.outroDialogueId}");
if (GameStateManager.Instance != null)
GameStateManager.Instance.TransitionTo(GameState.Dialogue);
if (DialogueSystem.Instance != null)
{
DialogueSystem.Instance.StartDialogue(CurrentChapter.outroDialogueId);
// Subscribe BEFORE starting — same fix as intro.
DialogueSystem.Instance.OnDialogueComplete += OnOutroDialogueComplete;
DialogueSystem.Instance.StartDialogue(CurrentChapter.outroDialogueId);
}
else
{
Debug.LogWarning("[CampaignManager] DialogueSystem no disponible. Saltando outro.");
CompleteChapter();
return;
}
if (GameStateManager.Instance != null)
GameStateManager.Instance.TransitionTo(GameState.Dialogue);
}
private void OnOutroDialogueComplete()
+16 -12
View File
@@ -30,9 +30,11 @@ public class DialogueUI : MonoBehaviour
void Update()
{
// Fallback: Space, Enter o clic izquierdo cuando no hay InputAction asignada
if (!_isInputEnabled) return;
if (_advanceDialogueAction != null) return; // el InputAction ya maneja esto
// If InputAction is configured, it handles input via OnAdvanceDialogueInput callback.
// Otherwise, fall back to keyboard/mouse.
if (_advanceDialogueAction != null && _advanceDialogueAction.action != null) return;
if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.Return) || Input.GetMouseButtonDown(0))
{
@@ -126,11 +128,11 @@ public class DialogueUI : MonoBehaviour
/// </summary>
private void OnNodeDisplayed(DialogueNode node)
{
_dialoguePanel.SetActive(true);
_continueIndicator.SetActive(false);
if (_dialoguePanel != null)
_dialoguePanel.SetActive(true);
if (_continueIndicator != null)
_continueIndicator.SetActive(false);
_isInputEnabled = true;
// El texto se actualiza mediante OnTextUpdated durante el typewriter
}
/// <summary>
@@ -149,10 +151,9 @@ public class DialogueUI : MonoBehaviour
/// </summary>
private void OnNodeComplete(DialogueNode node)
{
// Typewriter terminó, mostrar indicador
_continueIndicator.SetActive(true);
if (_continueIndicator != null)
_continueIndicator.SetActive(true);
// Iniciar parpadeo del indicador
if (_blinkCoroutine != null)
{
StopCoroutine(_blinkCoroutine);
@@ -165,7 +166,8 @@ public class DialogueUI : MonoBehaviour
/// </summary>
private void OnDialogueComplete()
{
_dialoguePanel.SetActive(false);
if (_dialoguePanel != null)
_dialoguePanel.SetActive(false);
_isInputEnabled = false;
if (_blinkCoroutine != null)
@@ -212,9 +214,11 @@ public class DialogueUI : MonoBehaviour
{
while (true)
{
_continueIndicator.SetActive(true);
if (_continueIndicator != null)
_continueIndicator.SetActive(true);
yield return new WaitForSecondsRealtime(_blinkSpeed);
_continueIndicator.SetActive(false);
if (_continueIndicator != null)
_continueIndicator.SetActive(false);
yield return new WaitForSecondsRealtime(_blinkSpeed);
}
}
File diff suppressed because it is too large Load Diff
+7056 -1441
View File
File diff suppressed because it is too large Load Diff
+7605 -1990
View File
File diff suppressed because it is too large Load Diff