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

Resolved UnityEvents and EditorWindow

Discussion in 'Scripting' started by InnerCoder, May 17, 2021.

  1. InnerCoder

    InnerCoder

    Joined:
    Nov 16, 2020
    Posts:
    15
    Hello,

    I work with Unity 2019. I'm coding a MonoBehaviour class where there is an UnityEvent public field. And I want to create an EditorWindow for that script.

    Others fields are correctly displayed. But I don't know how to display the UnityEvent field in the EditorWindow. Even with a private variable declared in the EditorWindow, how do you show it?

    Thanks
     
    Last edited: May 17, 2021
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    EditorGUI.PropertyField and EditorGUILayout.PropertyField should show a UnityEvent field with its' custom drawer.
     
    Bunny83 and eses like this.
  3. InnerCoder

    InnerCoder

    Joined:
    Nov 16, 2020
    Posts:
    15
    Thanks for your reply. I tried and this message appeared in console :

    cannot convert from 'UnityEngine.Events.UnityEvent' to 'UnityEditor.SerializedProperty'
     
  4. InnerCoder

    InnerCoder

    Joined:
    Nov 16, 2020
    Posts:
    15
    I made a mistake : the event is declared not in the MonoBehaviour class directly but in a another class, and this last one is instancied as a public field.

    So I found the solution with
    SerializedObject(target)
    and later with
    FindPropertyRelative()
    .

    Thank you
     
    Last edited: May 17, 2021
    GroZZleR likes this.