How to check for Start and End of conversation via code

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Saper
Posts: 52
Joined: Tue Jan 12, 2021 11:25 am

How to check for Start and End of conversation via code

Post by Saper »

Hi Tony

I want to setup a variable to change on "Start" and "End" of every conversation. I found events:
- OnConversationStart()
- OnConversationEnd()
can I setup my variable by monitoring those events?

Also if i use method "DialogueManager.StopConversation()", OnConversationEnd() would be propagated or not?

Also is there another method to check for end and start of conversation?
DarkProphet
Posts: 15
Joined: Thu Dec 16, 2021 2:09 pm

Re: How to check for Start and End of conversation via code

Post by DarkProphet »

I believe this is what you're looking for:

Code: Select all

DialogueManager.instance.conversationStarted += MyConversationStarted;
DialogueManager.instance.conversationEnded += MyConversationEnded;
// make your own functions like this:
private void MyConversationEnded(Transform t){}
Hope that helps!

PS: Remember to unsubscribe (-=) to the events in OnDestroy or whatever, depending on how your code works!

Code: Select all

DialogueManager.instance.conversationStarted -= MyConversationStarted;
Saper
Posts: 52
Joined: Tue Jan 12, 2021 11:25 am

Re: How to check for Start and End of conversation via code

Post by Saper »

I was thinking about somthing like this:

Code: Select all

public class DialogueConversationMonitor : InjectableMonoBehaviour
{


    public override void DependenciesResolved()
    {
        EventSystem.Receive<OnConversationStart>().Subscribe(x => ChangeConversationStateToTrue()).AddTo(this);
        EventSystem.Receive<OnConversationEnd>().Subscribe(x => ChangeConversationStateToFalse()).AddTo(this);
    }

    private void Update()
    {

    }

    private void ChangeConversationStateToTrue()
    {
            DialogueLua.SetVariable("InConversation", true);
    }

    private void ChangeConversationStateToFalse()
    {
            DialogueLua.SetVariable("InConversation", false);
    }

}
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to check for Start and End of conversation via code

Post by Tony Li »

Hi,

No need for that. I recommend DarkProphet's method above.
Post Reply