Hi there, i’ve been trying to register a callback from flowcanvas to access the new Unity UI Toolkit Elements but i can’t really find a proper way that works.
The code i’m trying to replicate would be : visualElement.Registercallback<MouseDownEvent>(Myfunction);
You will need to add the corresponding types to the Preferred Types Editor. For this case that means adding the visualElement class type you are using, as well as the MouseDownEvent class type. Once both are in the Preferred Types Editor, you should be able to see the visualElement type in the Reflected category and use its methods.
I’ve tried all that but the reflected method returns an error/null node when you try using it. That’s why i was trying to do it manually.
You can test what i’m saying cause it’s a consistent bug, i’m using the last Flowcanvas release as of this date and 2021.3.6f (also tested on newer versions) with the latest UI Toolkit release.
You are right. Because of the constrains the RegisterCallback has it is not handled correctly and an error is poped. I will need to correct this. For a quickfix however, you can open up ReflectedMethodNodeWrapper.cs file and comment lines #57 to #61 in the SetMethod method. Doing this will allow you to add the RegisterCallback method node. Just remember to right click on it once it is added and from the menu select “Change Generic Type” (to MouseDownEvent in this case).
The node gets called now but i get the “A Port is Null.” error and “No ports to connect to in this node.” errors, you cannot change the Type anywhere in this node.