Best way to enable/disable object after specific conversation ends? (From scene, not from dialogue database)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
wedgiebee
Posts: 16
Joined: Wed May 25, 2022 6:40 pm

Best way to enable/disable object after specific conversation ends? (From scene, not from dialogue database)

Post by wedgiebee »

Hello! I'm starting a conversation using a DialogueSystemTrigger, and when the conversation is done I'd like to deactivate a certain game object in the scene. I would like to set this functionality up without using the dialogue editor/database.

What is the best way to achieve this? I saw that the GameObjects assigned in the DialogueSystemTrigger's Actor and Conversant fields can use either DialogueSystemEvents or DialogueSystemTrigger's OnConversationEnded. BUT I'm using that Actor and Conversant in multiple conversations. It is only for one particular conversation between the two of them that I want to turn off a specific object, so I don't want that functionality to run every time the two of them have a conversation.

What's the best way to go about doing this? Thank you!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best way to enable/disable object after specific conversation ends? (From scene, not from dialogue database)

Post by Tony Li »

Hi,

If you don't want to use the Dialogue Editor or dialogue database, you could add a script with an OnConversationEnd method to the Dialogue Manager or one of the primary participants, or hook into the C# event DialogueManager.instance.conversationEnded. Example:

Code: Select all

public class DeactivateObjectOnConversationEnd : MonoBehaviour
{
    [ConversationPopup(true)] public string conversation;
    public GameObject target;
    
    void OnEnable() { DialogueManager.instance.conversationEnded += OnConversationEnded; }
    void OnDisable() { DialogueManager.instance.conversationEnded -= OnConversationEnded; }
    
    void OnConversationEnded(Transform actor)
    {
        if (DialogueManager.lastConversationStarted == conversation) target.SetActive(false);
    }
}

However, most people put this in the dialogue database, using either a SetActive() command in the Sequence field or a scene event. This way they don't have to maintain and debug extra code, and dialogue activity is contained in one place (the dialogue database).
wedgiebee
Posts: 16
Joined: Wed May 25, 2022 6:40 pm

Re: Best way to enable/disable object after specific conversation ends? (From scene, not from dialogue database)

Post by wedgiebee »

Hi, thanks for the help! I ended up solving it differently. I didn't realize that that the DialogueSystemTrigger that starts the conversation will also receive OnConversationEnded if I add another DialogueSystemTrigger on that same object, so now I'm doing that! So I can real cleanly on one GameObject have inspector-assigned events/actions that should take place when that trigger starts a conversation, and when that conversation ends.

Thanks for the note about just putting things in the dialogue database to prevent debugging extra code! Sometimes I get stuck thinking about where the best place to put things is, so I appreciate the advice. For my case, since I'm not doing much branching dialogue and really just using it as a way to organize linear text, most of my logic happens outside of the database so I figured it would be simpler for me to do it that way
Post Reply