0

Please help me how to show UnityEvent variable in custom editor.

Script:

public class BTNPattern : MonoBehaviour {
    public UnityEvent testEvent;
}

Editor script:

[CustomEditor(typeof(BTNPattern))]
public class BTNPatternEditor : Editor {
    public override void OnInspectorGUI() {
        BTNPattern myTarget = (BTNPattern) target;
        // what to put here to show myTarget.testEvent ?
}
4
  • It does show by default. No need for custom editor. Commented Feb 13, 2016 at 18:46
  • im using custom editor because of other variables and usefull way to work with its. Unity Event is just a problem, that appeared in my case Commented Feb 14, 2016 at 2:30
  • Possible duplicate of Unable to change array size in Inspector variable in Unity? Commented Feb 15, 2016 at 17:16
  • You can also draw the default inspector docs.unity3d.com/ScriptReference/… Commented Jan 26, 2021 at 10:07

1 Answer 1

1

Ok, I found a way:

SerializedProperty sprop = serializedObject.FindProperty("testEvent");
EditorGUIUtility.LookLikeControls();
EditorGUILayout.PropertyField(sprop);
serializedObject.ApplyModifiedProperties();
Sign up to request clarification or add additional context in comments.

1 Comment

I've removed all code that wasn't related to the Q, because OP was mixing another Q in the topic & reanswering in next answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.