How to check if a public method is referenced in inspector

Hi. I’m working on a project with tons of legacy C# code which isn’t very developer friendly. Many methods in classes are public even if they aren’t referenced outside of class. Some of those methods are connected to various objects in inspector (so they are called after you click a button or something) and I really don’t know how to check that. Is there a way to check if a public method from some class is referenced somewhere in the inspector?

I’m not aware of a built in way to do this in the Unity editor. But the function (not the component it’s called on) in a UnityEvent is simply serialised as the function name, so you can just search files for the name of the function, outside Unity.

I do this kind of stuff in bash using, for example…

To find all prefabs with a UnityEvent that invokes a function called FunctionName…

find . -name "*.prefab" -exec grep -l FunctionName {} \;

I would also search scene and scriptable object files which might contain UnityEvents - you may not have them in the latter. If necessary you can also search animation files this way (for functions being called from animation events).
There are of course other ways of doing it depending on your platform etc

Note that if you wanted to know that a function’s not being used anywhere, you’d also need to do a “find references” search in your IDE.

If those references are just regular UnityEvents, then you can get the method name and target object with GetPersistentMethodName and GetPersistentTarget.

You can use this for finding references to a method inside unity editor:

download the unitypackage file and use it according to help text