Callbacks for UI Toolkit

FlowCanvas Forums Support Callbacks for UI Toolkit

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #3332
    hitsu san
    Participant

    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);

    Any suggestion is appreciated!

    #3333
    Gavalakis
    Keymaster

    Hello there,

    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.

    Please let me know if that works for you.

    Thanks.

    Join us on Discord: https://discord.gg/97q2Rjh

    #3334
    hitsu san
    Participant

    Hello Gavalakis,

    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.

    #3336
    Gavalakis
    Keymaster

    Hello and sorry for the late reply.

    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).

    Let me know if that works for you.

    Join us on Discord: https://discord.gg/97q2Rjh

    #3342
    hitsu san
    Participant

    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.

    #3344
    Gavalakis
    Keymaster

    Hello again. I just re-tried and it seems to be working. This is what I did:

    • Open Preferred Types Editor and add the ‘Visual Element’ type as well as the ‘MouseDownEvent’ type in the list.
    • Made the changes to ReflectedMethodNodeWrapper.cs I mentioned above.
    • Add node “Register Callback (T) from the node browser.
    • Right click the node and in the menu select ‘Change Generic Type’ to “MouseDownEvent”.

    RegisterCallbackChangeGenericType

    Please let me know, or if you can please share a screenshot of your graph to see how you are connecting things up.

    Thanks.

    Join us on Discord: https://discord.gg/97q2Rjh

    Attachments:
    You must be logged in to view attached files.
    #3346
    hitsu san
    Participant

    Ok the node works now! Although i cannot find a way to register a proper callback to do this simple code:

    Attachments:
    You must be logged in to view attached files.
    #3351
    Gavalakis
    Keymaster

    Hello,

    You can use the node named “Delegate Callback” to hook up delegates.

    Let me know if that works for you. Thanks.

    Join us on Discord: https://discord.gg/97q2Rjh

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.