What's the right way(s) (using the editor/script) to run a script's function when a conversation ends?
I've tried the Dialogue System Events component, which works perfectly, but using that, the same function would run at the end of any conversation the player has, and not at the end of the specific conversation I need it to..
Thanks.
Running a script when a conversation ends
Re: Running a script when a conversation ends
Hi,
If it's okay to run the script in the last dialogue entry of the conversation, you can use a SendMessage() sequencer command or an OnExecute() scene UnityEvent.
If the script only needs to run after talking with a specific NPC, you can add the Dialogue System Events component to the NPC.
Otherwise, you can add a script with an OnConversationEnd() method to the Dialogue Manager or player, and check if a specific conversation has ended.
If it's okay to run the script in the last dialogue entry of the conversation, you can use a SendMessage() sequencer command or an OnExecute() scene UnityEvent.
If the script only needs to run after talking with a specific NPC, you can add the Dialogue System Events component to the NPC.
Otherwise, you can add a script with an OnConversationEnd() method to the Dialogue Manager or player, and check if a specific conversation has ended.
Code: Select all
public class RunScriptWhenConversationEnds : MonoBehaviour
{
[ConversationPopup] public string conversation;
void OnConversationEnd(Transform actor)
{
if (DialogueManager.lastConversationStarted == conversation)
{
// (run your script)
}
}
}
Re: Running a script when a conversation ends
First of all thanks very much for replying during Christmas. Most appreciated!
My Player has the following script as one of it's components - But when I use SendMessage(SetSearchingPocketsEvent, speaker), nothing happens - Any observations?
My Player has the following script as one of it's components - But when I use SendMessage(SetSearchingPocketsEvent, speaker), nothing happens - Any observations?
Re: Running a script when a conversation ends
Since the node is gray, the speaker is almost certainly the NPC, not the player. Assuming Ben is the player, this mean's he's this node's listener. Try this command:
Note that the SendMessage() command actually has 3 arguments. The middle argument is blank because SetSearchingPocketsEvent() doesn't have any parameters.
Code: Select all
SendMessage(SetSearchingPocketsEvent, , listener)