Page 1 of 1

Invoke SequenceEvent callbacks in script?

Posted: Wed Jan 15, 2025 7:27 pm
by windupthing
Hi, I'm wondering if there's a way to invoke DialogueSystemEvents and SequenceEvents in the script, in the same way that you can invoke UnityEvents to use the callbacks inside them. I want to manually invoke the same callbacks that I defined in the SequenceEvents component in a different script. I'm also trying to specifically get the OnSequenceEnd event callbacks.

In the code below, the testEvent recognizes the UnityEvent on the dialogueTrigger object, and fills out the testEvent with the same callbacks as the dialogueTrigger has. It does not fill out anything for the sequenceEvent callbacks, in either OnSequenceStart or OnSequenceEnd.

Thanks in advance! Let me know if there's any other context/code I should send.

Code: Select all

  
using UnityEngine.Events;
using PixelCrushers.DialogueSystem;
  
public DialogueSystemEvents.SequenceEvents sequenceEvent; 
public UnityEvent testEvent; 

    void Awake()
    {
    	//this fills out the testEvent callbacks in the inspector
        testEvent = dialogueTriggers.GetComponent<EventTest>().m_MyEvent; 
        //this leaves the sequenceEvent callbacks empty
        sequenceEvent = dialogueTriggers.GetComponent<DialogueSystemEvents.SequenceEvents>();
    }

    private void Start()
    {
    	//this runs the callbacks in the testEvent
        testEvent.Invoke();
        //invoke isn't the correct method to use here, not sure what i should write instead
        sequenceEvent.Invoke();
    }

Re: Invoke SequenceEvent callbacks in script?

Posted: Wed Jan 15, 2025 9:49 pm
by Tony Li
Hi,

Since you're writing a script anyway, it might be simpler to use the [OnSequence***() methods](https://pixelcrushers.com/dialogue_syst ... esSequence), which are the same methods that the DialogueSystemEvents component uses. The [Script Messages](https://pixelcrushers.com/dialogue_syst ... ptMessages) section has tables that explain which GameObjects receive which messages.

Re: Invoke SequenceEvent callbacks in script?

Posted: Thu Jan 16, 2025 12:01 pm
by windupthing
Hi Tony, thanks for the quick response! I had seen those options before, but wasn't sure they were what I needed, but I might also be tunnel-visioning with one angle here? So, I have GameObject A, a dialogue trigger that plays a sequence, and it also has a few functions listed as callbacks in the OnSequenceEnd section of its inspector.

In GameObject B, I'd like to be able to invoke all the same functions listed as callbacks in the dialogue trigger acting as though the sequence had played and ended but without actually playing the sequence itself. This is basically to bypass the cutscene visually but get all the results of the functions happening.

I can manually copy and paste all the callbacks from the OnSequenceEnd from GameObject A into GameObject B, but I'm wondering if there's a better way to have GameObject B automatically recognize and populate itself with GameObject A's callbacks. For example, B is able to populate regular UnityEvents from A and that works well.

A's inspector (has sequence events and UnityEvents):
Image

B before runtime (all callbacks are empty):
Image

B at runtime (only UnityEvents got populated):
Image

Re: Invoke SequenceEvent callbacks in script?

Posted: Thu Jan 16, 2025 4:07 pm
by Tony Li
Hi,

What if you set it up like this:

1. [Design time] On GameObject B, add a Dialogue System Trigger set to OnUse. In Actions > OnExecute() UnityEvent, configure the events that should happen whether there's visual activity or not.

2. [Design time] On GameObject A's OnSequenceEnd() UnityEvent, call GameObjectB's DialogueSystemTrigger.OnUse.

3. [At runtime[ Add the event listeners to GameObjectB's onExecute UnityEvent.

If you trigger GameObject A, it will play its sequence and then run GameObject B's OnExecute() UnityEvent.

If you bypass A and trigger GameObject B's OnUse() directly instead, it will just run GameObject B's OnExecute() UnityEvent.

Re: Invoke SequenceEvent callbacks in script?

Posted: Wed Jan 29, 2025 1:43 pm
by windupthing
Hi Tony, sorry for the late reply! I just wanted to return to say this works perfectly and exactly as intended. Thanks so much for the advice and direction here - I was definitely tackling things from the same angle over and over so I appreciate the fresh look here.

Re: Invoke SequenceEvent callbacks in script?

Posted: Wed Jan 29, 2025 4:29 pm
by Tony Li
Happy to help! Glad it's all working now.