Easily inspect callbacks on UnityEvents with UnityEventDebugger, a reflection-based solution to see which methods will be called upon invoking a UnityEvent.
I don't think there will be many changes in the future, but if there are, they will first be tested on the master branch and then being released properly once I'm sure it still works fine. This being said, the latest stable release of this tool will always be available on the latest release branch of this repository but you can also just use the master-branch.
Coming soon!
Inside of the unity project there is a folder called Packages. It will contain the newest release version as a .unitypackage. Download it and import it from within the editor:
Simply navigate to the packages file location on your pc inside of the resulting pop-up and select everything.
You can also just download/clone the repository and import the files into your project manually. To do so, just drag and drop the UnityEventDebugger folder into your project.
The UnityEventDebugger comes with a built-in property drawer to inspect UnityEvents. The property drawer simply inherits the normal property drawer and draws any additional information onto the inspector. The enhanced drawer looks exactly like the one you see in the screenshot at the top!
You can build whatever tool you want off this. The information about which callbacks a specific event invokes can be retrieved by calling UnityEventHelper.GetCallbacksOnObjectForEvent(Object theObject, string eventName)
inside your own code.
It returns a list of UnityEventMethodContextHolder
, a class that maps an event name to a method call and its context object. It supports three public properties:
ClassName.MethodName
, indicating which method will be called upon invoking the event.You can use these in your tools to display the information wherever and however you want.
You can configure a bunch of settings in the Unity Preferences window. Just go to Edit -> Preferences -> UnityEventDebugger and you will see the following settings window:
It is quite simple:
I've made a small helper method UnityEventHelper.GetCallbacksOnObjectForEvent(Object theObject, string eventName)
that does the magic.
Inside of it, I use reflection to find the member variable of the UnityEvent. Every UnityEvent internally uses a variation of BaseInvokableCall with its respective generic arguments, e.g. UnityEventdelegate.GetInvocationList()
to retrieve all methods that will be invoked and their context object.
Thats it!