jacobdufault / fullinspector

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

BaseScriptableObject that implements IList<T> breaks inspector #214

Open franklin-ross opened 6 years ago

franklin-ross commented 6 years ago

I haven't dug too deeply, but it seems like having a class that implements both BaseScriptableObject and IList<T> uses the BaseCollectionPropertyEditor which throws a NullReferenceException. I guess the order of some code somewhere needs to be updated so it decides to render as a ScriptableObject instead.

The error looks like this:

NullReferenceException: Object reference not set to an instance of an object
FullInspector.Internal.BaseCollectionPropertyEditor`4[TActual,TCollection,TItem,TAddItem].ShouldDisplayPageControls (TCollection collection) (at Assets/FullInspector2/Modules/Collections/Editor/BaseCollectionPropertyEditor.cs:338)
FullInspector.Internal.BaseCollectionPropertyEditor`4[TActual,TCollection,TItem,TAddItem].GetElementHeight (UnityEngine.GUIContent label, TCollection collection, FullInspector.fiGraphMetadata metadata) (at Assets/FullInspector2/Modules/Collections/Editor/BaseCollectionPropertyEditor.cs:582)
FullInspector.PropertyEditor`1[TElement].FullInspector.IPropertyEditorEditAPI.GetElementHeight (UnityEngine.GUIContent label, System.Object element, FullInspector.fiGraphMetadata metadata) (at Assets/FullInspector2/Core/Editor/IPropertyEditor.cs:84)
FullInspector.PropertyEditorExtensions.GetElementHeight[T] (FullInspector.IPropertyEditor editor, UnityEngine.GUIContent label, T element, FullInspector.fiGraphMetadataChild metadata) (at Assets/FullInspector2/Core/Editor/IPropertyEditorExtensions.cs:256)
FullInspector.Internal.fiEditorGUI.EditPropertyHeightDirect (FullInspector.InspectedProperty property, System.Object propertyValue, FullInspector.fiGraphMetadataChild metadataChild) (at Assets/FullInspector2/Core/Editor/fiEditorGUI.cs:367)
FullInspector.Internal.fiEditorGUI.EditPropertyHeight (System.Object container, FullInspector.InspectedProperty property, FullInspector.fiGraphMetadataChild metadata) (at Assets/FullInspector2/Core/Editor/fiEditorGUI.cs:372)
FullInspector.Internal.ReflectedPropertyEditor.GetElementHeight (UnityEngine.GUIContent label, System.Object element, FullInspector.fiGraphMetadata metadata) (at Assets/FullInspector2/Core/Editor/PropertyEditors/ReflectedPropertyEditor.cs:395)
FullInspector.PropertyEditorExtensions.GetElementHeight[T] (FullInspector.IPropertyEditor editor, UnityEngine.GUIContent label, T element, FullInspector.fiGraphMetadataChild metadata) (at Assets/FullInspector2/Core/Editor/IPropertyEditorExtensions.cs:256)
FullInspector.DefaultBehaviorEditor.OnGetHeight (UnityEngine.Object behavior, FullInspector.fiGraphMetadata metadata) (at Assets/FullInspector2/Core/Editor/DefaultBehaviorEditor.cs:47)
FullInspector.BehaviorEditor`1[TBehavior].GetHeight (UnityEngine.Object behavior) (at Assets/FullInspector2/Core/Editor/IBehaviorEditor.cs:112)
FullInspector.IBehaviorEditorExtensions.EditWithGUILayout[T] (FullInspector.IBehaviorEditor editor, T element) (at Assets/FullInspector2/Core/Editor/IBehaviorEditorExtensions.cs:17)
FullInspector.FullInspectorCommonSerializedObjectEditor.ShowInspectorForSerializedObject (UnityEngine.Object target) (at Assets/FullInspector2/Core/Editor/FullInspectorCommonSerializedObjectEditor.cs:177)
FullInspector.FullInspectorCommonSerializedObjectEditor.OnInspectorGUI () (at Assets/FullInspector2/Core/Editor/FullInspectorCommonSerializedObjectEditor.cs:193)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, System.Int32 editorIndex, System.Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1245)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
franklin-ross commented 6 years ago

In fact this seems true for pretty much any collection like IDictionary<T,TV>, or even IEnumerable<T>. Is this by design?

I've been creating ScriptableObjects that implement these so I can share the data via the editor, but it's nice to have them implement the interface they represent.

franklin-ross commented 6 years ago

I tried using SharedInstance, as that seems to be the FullInspector way to do what I'm trying, but I get compile errors in the generated shared instance file:

[SerializeField]
public SharedInstance<Dictionary<BlockKind, GameObject>> BlockPrefabs;

Where the generated code is:

// This is an automatically generated script that is used to remove the generic 
// parameter from SharedInstance<T, TSerializer> so that Unity can properly serialize it.

using System;

namespace FullInspector.Generated.SharedInstance {
    public class SharedInstance_SystemCollectionsGenericSystem_Collections_Generic_Dictionary_BlockKind,UnityEngine_GameObject_ : SharedInstance<System.Collections.Generic.Dictionary<BlockKind,GameObject>> {}
}

I have discovered how to fix the generated code, so I've got a workaround for now.