Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Is there an equivalent of UnityEvent to add to a VisualElement?

Discussion in 'UI Toolkit' started by TheRealRan, Apr 26, 2021.

  1. TheRealRan

    TheRealRan

    Joined:
    Jun 3, 2019
    Posts:
    18
    I would like to add a UnityEvent to my GraphView nodes if I could, however I do not seem to find something that allows me to do so.

    Is there any built-in UI element that allows me to have that?

    I would like to transfer that to a scriptable object as well.
     
  2. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    515
    TheRealRan likes this.
  3. TheRealRan

    TheRealRan

    Joined:
    Jun 3, 2019
    Posts:
    18
    I'm not entirely sure how to use that one (to be honest, I did not understand what part of that post creates an UnityEvent using IMGUI, or how could it be used on a Node) but I'll try to find it.

    Thank you!
     
  4. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    515
    I may have misunderstood what you are trying to do so don't hesitate to provide more context. The code snippet from @Xenerade create a visual element that will modify a property of a serializedObject.

    For this to work, you need to use a monobehavior or a scriptableObject that contain the UnityAction and pass the name of the property as a parameter to the method.

    Once you have that visual element, you will be able to add it to your hierarchy in your graph and modify the value accordingly.
     
    TheRealRan likes this.
  5. TheRealRan

    TheRealRan

    Joined:
    Jun 3, 2019
    Posts:
    18
    I was trying to add an UnityEvent element to a node (GraphView.Node) on the Graph (experimental GraphView) on my custom editor window (much like the one in the image on that post).

    I'm new to UI and such so it may be just misunderstanding, but it doesn't seem to be what I'm looking for, or perhaps I'm just not really understanding, as I'm new to this.

    I would like something to do
    Code (CSharp):
    1. node.extensionContainer.Add(UnityEventElement);
    for example.