Search Unity

SerializedProperty to UnityEvent

Discussion in 'Editor & General Support' started by UselessPotato, Jan 15, 2019.

  1. UselessPotato

    UselessPotato

    Joined:
    Jan 15, 2019
    Posts:
    1
    I am currently facing an issue in converting a SerializedProperty to a UnityEvent.

    Thats how I declare it in the main script

    Code (CSharp):
    1. public UnityEngine.Events.UnityEvent EventToAdd;
    And this is my Editorscript

    Code (CSharp):
    1. private SerializedProperty _Events;
    2. private void OnEnable()
    3.    {
    4.        _Events = serializedObject.FindProperty("EventToAdd");
    5.    }
    6.  
    7.  
    8. public override void OnInspectorGUI()
    9.    {
    10. TwitchTVGui TGUI = (TwitchTVGui)target;
    11.  
    12.        this.serializedObject.Update();
    13. EditorGUILayout.PropertyField(this.serializedObject.FindProperty("EventToAdd"), true);
    14.            this.serializedObject.ApplyModifiedProperties();
    15. }
    And then I need to get the UnityEvent out of the serializedObject _Events

    BR, Torben