Draw inspector for custom types

Aleksandr Zhdanov 4 years ago updated by Lazlo Bonin (Lead Developer) 4 years ago 10

I have two types: TestScript structure and class TestClass: type definition.

When I add them to the board, I do not see the appropriate inspectors: object with Variables component.

It would be desirable, that it worked, as in FlowCanvas: FC editor for structure, also it is necessary to notice that FlowCanvas allows to create an instance of object of a class: FC editor with instantiated object.
Is it possible to fix that? Or only way to resolve it, is to create custom inspector for my type?

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Satisfaction mark by Aleksandr Zhdanov 4 years ago

Ok, i add custom property drawer for TestClass:

public class TestClassDrawer : PropertyDrawer
    public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        SerializedProperty scale = prop.FindPropertyRelative("myVar");

Now in inspector i see it:  Error in variable property in Variables

Error message from log:

InvalidOperationException: Missing property provider for 'TestClass'.
Did you generate serialized property providers?
  at Ludiq.SerializedPropertyUtility.CreateTemporaryProperty (System.Type type) [0x0001b] in C:\Users\Lazlo\Projects\Ludiq\Ludiq.Core\Editor\SerializedProperties\SerializedPropertyUtility.cs:99 
  at Ludiq.CustomPropertyDrawerInspector.Initialize () [0x00006] in C:\Users\Lazlo\Projects\Ludiq\Ludiq.Core\Editor\Inspection\Special\CustomPropertyDrawerInspector.cs:15 
  at Ludiq.InspectorProvider.CreateDecorator (Ludiq.Metadata metadata) [0x00063] in C:\Users\Lazlo\Projects\Ludiq\Ludiq.Core\Editor\Inspection\InspectorProvider.cs:24 
  at Ludiq.SingleDecoratorProvider`3[TDecorated,TDecorator,TAttribute].GetDecorator (.TDecorated decorated) [0x0008d] in C:\Users\Lazlo\Projects\Ludiq\Ludiq.Core\Editor\Decorators\SingleDecoratorProvider.cs:66 
  at Ludiq.XInspectorProvider.Inspector (Ludiq.Metadata metadata) [0x00000] in C:\Users\Lazlo\Projects\Ludiq\Ludiq.Core\Editor\Inspection\InspectorProvider.cs:167 
  at Ludiq.LudiqGUI.GetInspectorHeight (Ludiq.Inspector parentInspector, Ludiq.Metadata metadata, Single width, UnityEngine.GUIContent label) [0x00000] in C:\Users\Lazlo\Projects\Ludiq\Ludiq.Core\Editor\Interface\LudiqGUI.cs:48 
  at Ludiq.SystemObjectInspector.GetHeight (Single width, UnityEngine.GUIContent label) [0x00036] in C:\Users\Lazlo\Projects\Ludiq\Ludiq.Core\Editor\Inspection\Special\SystemObjectInspector.cs:215 
  at Ludiq.Inspector.GetCachedHeight (Single width, UnityEngine.GUIContent label, Ludiq.Inspector parentInspector) [0x00042] in C:\Users\Lazlo\Projects\Ludiq\Ludiq.Core\Editor\Inspection\Inspector.cs:159 
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)

Any thoughts?

Pending Review

It's exactly like the error says, you need to generate the providers.

I'm on my phone at the moment, but I think the generator is located under Tools > Ludiq > Generate Inspectors.

Let me know if it works then!

Heh, now it's works!

So, my story.
At first, my type existed in global space. I added my type in Unit Options Withard > Types, saw it in {global} section in Variables, next i wrote custor property drawer for type, but got error message from above post: error message.

I decided looking into Generated > Property Provider > my type provider and noticed, provider class name and file name was exactly like my own type (TestClass : Ludiq.SerializedPropertyProvider<TestClass>, TestClass.cs). First, i renamed provider type to Test_Class, error disapear, but fields still no drawn: inspector without fields

After that i renamed provider filename and voila! All works! inspector with fields
So, seems like some name collision.

To confirm the guess, i moved my class and inspector to own namespace, added new type in Unit Options Withard, regenerated custom ispector and all worked.
P.S. For some reasons EditorGUILayout doesn't work properly in PropertyDrawer, so it is necessary use EditorGUI. strange field draw with EditorGUILayout

Glad you got it fixed!

Yes, EditorGUILayout never works in property drawers, that's a Unity limitation (unrelated to Bolt).

Can you explain again what was the name conflict? 

I want the process to be a 1-click operation (Generate Inspectors), without anyone having to manually rename or edit the generated script files. Please let me know what the automatic name was and what it should have been for it to work, because I didn't understand from your post.



Sorry for late response. For better explanation how i fixed it, i recorded video, hope this help you. http://take.ms/mvnJD

Ah, I see! Thanks for the detailed video. It's just a matter of the name converter not respecting underscores, should be an easy fix.

Glad to help you :-)
It is possible add generation of property drawers for types in Unit Options Wizard > Type Options? Maybe when we generating custom inspector add check, if CustomPropertyDrawer attribute extist for current type and if nothing found - generate simple property drawer, like in my implementation.


I'll be trying something experimental in the next version for this. Please let me know if it works for you.

Basically, you will be able to add the [Inspectable] attribute to your class, as well as to any field/property you want to inspect. From then, you shouldn't need to create a custom editor or generate inspectors, and Bolt should be able to inspect it automatically. You won't need the [Serializable] attribute either (if you only use it from Bolt).  For example:

using Ludiq;
public class TestClass
    public string name;
    public int health;
    public bool someOtherHiddenProperty;

Another advantage with this is that you can also use properties ({ get; set; }) and private/protected members.

Works for variables:

And even for literals in flow graphs!

Fixed in Alpha

Added a PropertyProvider_ prefix to class and script names to prevent this error, should be fixed in next version.