Calling a Method Using Game Event Scriptable Object

I’m trying to use a scriptable object Game Event and Game Event Listener to call keep dependencies low and things more modular. How it’s formatted right now is I’m using a UnityEvent startScene, which OnTriggerEnter() is invoked. Here’s That Code:

private void OnTriggerEnter(Collider other)
{
    //if player
    if(other.tag == "Player")
    {
        //raise
        startScene.Invoke();
        Debug.Log("Invoked");

    }
}

Then this is the event in editor. From here, I am using my own Game Event, and “raising” it as a response to Start Scene(). I then have a Game Event Listener elsewhere in my scene that looks like this:

I believe this should be triggered on the raising of that Game Event PlayCutscene, and then call to my MonoBehavior CutsceneManager, specifically .startNextCutscene():

 //Starts next cutscene
public void startNextCutscene()
{
    Debug.Log("Signal Received");

    //Starts cutscene
    other.cutsceneStart((listOfScenes[selection]));
    Debug.Log("start?");
    //Increments cutscenes
    selection++;
}

(so this is sort of a side issue, but “other” is a MonoBehavior class that I created, and I just needed a way to call a specific method from it, so I declared other as an instance of that class and then made a call on it to give the method a value from my List of PlayableDirectors. Like I said, this is a side issue but any advice would be greatly appreciated.)

but this is my bug: I’ll get the Debug “Invoked” but not the “Signal Received”.
Any help, tips, or advice would be really greatly appreciated, thank you for any time you put in to help me here in advance!

Hi @Fender001

You don’t show all your code and the explanation is a bit hard to follow… but the issue I see is I don’t see where you subscribe your listener to listen the target event.

You should have something like this - what you already actually have in your event trigger:

myEvent.Invoke();

Then in your scene object that listens to this event:

public class EventListener : MonoBehaviour
{
    public CodeInSO soContainer;

    void Start()
    {
        Debug.Log("Added listener");
        FindObjectOfType<EventTrigger>().myEvent.AddListener(soContainer.DoSomething);
    }
}

Or you can manually drag the event listener to your event trigger (as it is UnityEvent, it will have a UI to add listener methods to), and set the called method there. Doesn’t matter if you do it like this or not.

It doesn’t matter either, if the script run is in ScriptableObject like here, or in MonoBehaviour, as long as the SO is linked somehow to a script that is in scene.

1 Like

Thank you very much!