Activate conversation entry from any point on event

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Deadcow
Posts: 28
Joined: Tue Apr 30, 2019 8:21 am

Activate conversation entry from any point on event

Post by Deadcow »

Imagine text quest represented as a huge dialogue tree. There a lots of entries, where player health might be decreased. I've got node tree called "Dead" and I'd like this node to activated when health is 0, regardless of current active entry.
One way to do this is to add links from all entries where hp is decreased to "Dead" entry with condition, but I wonder if there some way to activate it by some event automatically?

I handle dialogues mostly via code. I bind some custom Lua functions to Dialogue System to get or set current hp, items etc, so I imagine there should be some way to get current conversation, find entry named "Dead" and set it active if there is any... Is it possible?
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Activate conversation entry from any point on event

Post by Tony Li »

Yes. I'll describe two approaches: one using scripting, one without scripting.

I've debated adding an "Any State" like in Mecanim, but like with Mecanim it could cause performance issues if Any State links to a lot of nodes with Conditions, since it would need to evaluate these nodes' Conditions every time. So I haven't added this. If enough people really want it, I'll add it.

Without scripting, you can set up something that stops the conversation if health is 0. Add another Dialogue System Trigger set to OnConversationEnd with a Condition that checks if health is 0. If so, Add Action > Start Conversation and specify a starting entry ID. The downside of this approach is that you need to stop the conversation and restart it at the "Dead" node.

With scripting, you can keep the same conversation active. Call DialogueManager.conversationModel.GetState(entry), passing it a DialogueEntry. This returns a ConversationState, which you can then pass to DialogueManager.conversationController.GotoState(state).
Deadcow
Posts: 28
Joined: Tue Apr 30, 2019 8:21 am

Re: Activate conversation entry from any point on event

Post by Deadcow »

Okay, second option fits the best, but I wonder how to find needed entry from current Conversation?
Well actually it's easy to get entry from Conversation, but I was unable to find the way to get current Conversation, considering that conversation initially started by string id. I browsed api for DialogueManager, ConversationState, ConversationModel and ditn't found a way to get current Conversation :roll:
Last edited by Deadcow on Fri Sep 06, 2019 10:32 am, edited 1 time in total.
Deadcow
Posts: 28
Joined: Tue Apr 30, 2019 8:21 am

Re: Activate conversation entry from any point on event

Post by Deadcow »

Oh I found DialogueManager.MasterDatabase.GetConversation() method, should do the trick. Thanks! I'll try it now
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Activate conversation entry from any point on event

Post by Tony Li »

Sounds good. If you run into any issues, just let me know.
Post Reply