jacobdufault / fullinspector

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

"Proxy editor for Gradient" leaking #190

Open SugoiDev opened 7 years ago

SugoiDev commented 7 years ago

A new object is being created after each assembly reload when we have a gradient property in a behavior. I'm drawing the inspector using the toolkit.

@jacobdufault could this be related to the lack of multi-scene support?

screenshot 2016 11 14-02 11 44

SugoiDev commented 7 years ago

This actually happens for anything using the proxy editors.

A quick fix is below (might submit a PR when I have more time).

Just replace the MetadataObject implementation with the given one, on the file fiGenericPropertyDrawerPropertyEditorManager.cs

private GameObject MetadataObject {
    get {
        if (s_metadataObject == null) {
            var name = "Proxy editor for " + typeof(T).CSharpName();

            // note: using HideFlags.HideAndDontSave includes
            //       HideFlags.NotEditable
            var flags = HideFlags.HideInHierarchy | HideFlags.DontSave;
            s_metadataObject = GameObject.Find(name);

            if (s_metadataObject == null) {
                s_metadataObject = EditorUtility.CreateGameObjectWithHideFlags(name, flags);
            }
    }

There's another issue with those proxies: they break using serializedObject.targetObject in the drawers. If you have something like this

public override void OnGUI( Rect position, SerializedProperty property, GUIContent label ) {
    var behaviour = property.serializedObject.targetObject as MonoBehaviour;
                var animator = behaviour.GetComponent<Animator>();
}

Then your animator will be null, since the targetObject is actually the proxy container, not the object itself.

I did a bit of work on this, to make the containers be stored in the object itself (with proper hideflags), but I gave up because I was getting nowhere. I may open another issue with further details eventually.