Assigning private functions from scripts in a Unity Event? (Or should I just make them public?)

I’ve been looking for a better way to handle a global event system without using singletons, as I understand the issues they can have. I also understand their use as well, but this isn’t the topic I wanted to address. I was watching a presentation on Game Architecture with Scriptable Objects, and wanted to understand how to incorporate the event system he discusses (at 27:50) in my own projects. I took the code for the GameEvent ScriptableObject and the GameEventListener MonoBehavior, and put them into a test project. I wanted to create a test event trigger to begin typing some dialogue on the screen, which I have already programmed.

I have a private StartDialogue() function in my dialogue manager script attached to my dialogue manager game object. StartDialogue() begins typing out some test dialogue. However, I cannot access this function in the GameEventListener script I add to my dialogue manager game object. This is because the function is private.


(You can see that there is the EnterDialogueMode(TextAsset) function available, but I’ll mention that in a bit…)
Is there some way I can access the StartDialogue() function in the GameEventListener without making the function public? Or, is it fine to make it public? If this event system works well for me, I’ll be using it extensively throughout my projects, which would require many public functions, which I thought was bad practice.

Second question… As I build my project bigger, it would be useful to have GameEvent Scriptable Objects with parameters. (This would allow me to use the EnterDialogueMode function through a GameEvent Scriptable Object, passing in a TextAsset for the dialogue). However, I don’t want to create a new script for each different event type. Is there a way I can make a editable list of required parameters for each GameEvent Scriptable Object? Basically, each time I create a new GameEvent Scriptable Object, I want to be able to specify how many and what kind of parameters are needed to call the event, so listening functions can use those parameters.

Thank you for any help!

In order for the function to show up in the UnityEvent dropdown list, it has to be public. That’s just how it works.

It’s bad practice to make something public when there’s no good reason for it to be accessed from outside the class. If you have a legitimate need for it to be accessed externally, then it’s fine to make it public.

Okay, thank you! I just wanted to make sure I was building good habits now, and was unsure if this was okay or not. If anyone has an answer to my second question, I would greatly appreciate it.