I have a class which I created a custom drawer for using the ParadoxNotion API ( it inherits from DrawerAttribute ). This works fine when used in a custom FlowCanvas event, but I would like to be able to use the drawer to display my class the desired way when I use variables of that type in the blackboard and also when objects of that class are passed in as parameters to functions I have FlowCanvas or NodeCanvas nodes for.
Is this possible? Right now, when I have a blackboard object of this type it displays the class name on a button ( I’d like to be able to control what is displayed on that button ) and then when I click on it I get a popup which just displays the public members of that class (I’d like to be able to control what is displayed there ).
When you want to create a drawer for an object (class), you need to create an ‘ObjectDrawer’ (derive from ObjectDrawer(T) ). This way, the object will be drawn with this drawer wherver it is encounter, including the popup editor when the Blackboard variable button has been pressed, as well as within the inspector when used as a parameter for example. Here is a simple example:
I implemented this, but it never appears to call my code at all.
The button on the blackboard variables window appears as before, but when the popup window opens the debug log doesn’t get called and the button doesn’t show. I tried putting the class in both a folder called Editor and a normal game folder ( not at the same time of course!) but neither one appeared to work.
public class StateFlagObjectDrawer : ObjectDrawer<StateFlagRef>
static string NO_FLAG_STR = “”;
bool open = false;
public override StateFlagRef OnGUI(GUIContent content, StateFlagRef flagRef)
(Not sure how to insert code on this forum, so apologies for any bad formatting!)
Update: On further debugging, when the code gets to EditorUtils::ReflectedFieldInspector for the variable of this class type, the parameters for field and attributes are both null, preventing it from finding the new drawer type, and instead reverting to the default drawer. Am I missing an attribute to get this to work?
Hmm. What FlowCanvas version are you using just to confirm?
The folder structure does not matter by the way, and no attribute is required for ObjectDrawer(T) to work.
Have you tried with the example “MyClass” and “MyClassDrawer” I posted above just for testing purposes?
Can you please post your code for StateFlagRef? Is it a class or a struct by the way (although this should not really matter)?
I tried with the MyClass sample you shared and I get the same problems. I was using version 2.8 and Unity 2017.4.0f1
After that, I just updated both NodeCanvas and FlowCanvas to the latest version on the Asset Store (2.92), and it works fine!
( I was previously getting some errors after the update, but spotted that was due to a similarly named function in a static class that somehow ended up being used by FlowCanvas, but changing the function name fixed the errors.