jacobdufault / fullinspector

Full Inspector supercharges Unity's inspector
MIT License
111 stars 27 forks source link

Editor callbacks can't get unregistered, so some methods that re-add themselves accumulate callbacks #185

Open hymerman opened 7 years ago

hymerman commented 7 years ago

I'm finding that FullInspector slows my game down gradually, because it's building up a huge number of callbacks. Anything that uses fiLateBindings.EditorApplication.RemUpdateFunc and AddUpdateFunc suffers from this, and there are some parts of FullInspector that add an update function every 0.3 seconds.

It looks like taking a copy of the Action in fiLateBindingsBinder, instead of storing it as an actual UnityEditor.EditorApplication.CallbackFunction prevents Unity recognising and removing the callbacks - it must be doing an object equality check.

Changing the code to not make a copy fixes this - but means that Unity editor types are exposed in non-editor code, meaning any calls to fiLateBindings.EditorApplication.RemUpdateFunc have to be guarded with #if UNITY_EDITOR. I'll submit a PR shortly; perhaps you can think of a better fix though!