Howdy folks. Testing out some aspects of a game I’ve been working on in an actual build. Most things are working correct except for one glaring problem.
I have a script to run dialogue when the player either interacts with a specific game object, or when they walk into a trigger area. Everything works fine in play mode. When I build and run the game, the interactable dialogue works, but none of the trigger area dialogue panels fire anymore. Adding logs and checking the build log shows that not only is the code not running but the OnTriggerEnter2D isn’t firing at all, it’s like the dialogue area doesn’t exist at all in the built scene.
Here’s what I’ve checked.
- The dialogue area game object is tagged appropriately with a tag that matches what the code is asking for.
- The dialogue area game object exists, it’s checked off in the hierarchy. It’s a child of a parent object and that object exists too.
- The dialogue script has the necessary dialogue data populated in the respective fields.
- Verified that the hasRun bool is not somehow checked already which would fail the whole thing.
- Verified that the player has the Player tag.
- Verified that collision is on between the player’s layer and the object’s layer.
Here’s a screenshot of the object in the hierarchy.
And the code for DialogueArea.cs.
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class DialogueArea : MonoBehaviour, IInteractable
{
public Dialogue dialogueData;
public GameObject dialoguePanel;
public GameObject partnerPanel;
public TMP_Text dialogueText, nameText, partnerText, partnerName;
public Image portraitImage, partnerPortrait;
BoxCollider2D areaCollider;
public int dialogueIndex;
private bool isTyping, isDialogueActive;
public bool hasRun = false;
public Conversation conversation;
private int turnIndex;
private Dialogue currentDialogue;
private TMP_Text currentText;
//if you have auto progressing lines you have to check the Auto Progress lines bool for EACH LINE ELEMENT that auto progresses.
void Start()
{
areaCollider = GetComponent<BoxCollider2D>();
}
void Update()
{
if (isDialogueActive && (Keyboard.current.escapeKey.wasPressedThisFrame || Keyboard.current.eKey.wasPressedThisFrame))
{
EndDialogue();
}
}
public bool CanInteract()
{
if (gameObject.CompareTag("DialogueArea")) return false;
return !isDialogueActive;
}
public void Interact()
{
if(dialogueData == null) return;
if(isDialogueActive)
{
NextLine();
}
else
{
StartDialogue();
}
}
void SwitchUIFor(Dialogue d)
{
bool partner = d.isPartner;
dialoguePanel.SetActive(!partner);
if (partnerPanel != null)
{
partnerPanel.SetActive(partner);
}
currentText = partner ? partnerText : dialogueText;
}
void StartDialogue()
{
isDialogueActive=true;
turnIndex = 0;
dialogueIndex = 0;
currentDialogue=conversation.turns[turnIndex];
SwitchUIFor(currentDialogue);
StartCoroutine(TypeLine());
//pause game if you have that set up
}
void NextLine()
{
if(isTyping)
{
StopAllCoroutines();
dialogueText.SetText(dialogueData.dialogueLines[dialogueIndex]);
isTyping=false;
return;
}
dialogueIndex++;
if(dialogueIndex < currentDialogue.dialogueLines.Length)
{
StartCoroutine(TypeLine());
return;
}
turnIndex++;
if(turnIndex < conversation.turns.Length)
{
dialogueIndex = 0;
currentDialogue = conversation.turns[turnIndex];
SwitchUIFor(currentDialogue);
StartCoroutine(TypeLine());
return;
}
EndDialogue();
}
IEnumerator TypeLine()
{
isTyping=true;
currentText.SetText("");
string line = currentDialogue.dialogueLines[dialogueIndex];
foreach(char letter in currentDialogue.dialogueLines[dialogueIndex])
{
currentText.text += letter;
SoundEffectManager.Play("Narrator Dialogue");
yield return new WaitForSeconds(dialogueData.typingSpeed);
}
isTyping = false;
if(currentDialogue.autoProgressLines != null &&
currentDialogue.autoProgressLines.Length > dialogueIndex &&
currentDialogue.autoProgressLines[dialogueIndex])
{
yield return new WaitForSeconds(dialogueData.autoProgressDelay);
NextLine();
}
}
private void HideHostPanel()
{
if (dialoguePanel != null)
{
dialogueText.SetText("");
dialoguePanel.SetActive(false);
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag("Player")) return;
if (hasRun) return;
if (gameObject.CompareTag(("DialogueArea")))
{
if(isDialogueActive)
{
NextLine();
}
else
{
StartDialogue();
hasRun = true;
}
}
}
public void EndDialogue()
{
StopAllCoroutines();
isDialogueActive = false;
if(dialoguePanel != null)
{
dialogueText.SetText("");
dialoguePanel.SetActive(false);
}
//unpause game if you have that
}
}
Why might the dialogue be triggering correctly in play mode but not in the build? Thank you all for your help.






