Can't see a public variable on a overloaded Event Trigger script
public class XXX: EventTrigger { public MusicToLoad musicToLoad = MusicToLoad.CURRENT; }
Hi all, I have the script above called XXX, which inherits from Event Trigger. However, when I try to use my own public enum MusicToLoad, it doesn't show up in this script.
Does the Event Trigger class block variables from being "seen" in the Inspector?
What should I do to workaround this issue? Thanks in advance for any help!
Best Regards, Jason
Answer by iBicha · Jul 29, 2017 at 12:54 AM
Hello Jason,
This is simply due to how the inspector for EventTrigger
works. Basically, other components need a CustomEditor
that inherits from Editor
, while EventTrigger
needs a EventTriggerEditor.
A simple solution is add a simple editor for it. In your Assets folder, create an Editor
folder if it doesn't exist already, create a XXXEditor.cs
, and put the following code:
using UnityEditor;
using UnityEditor.EventSystems;
[CustomEditor(typeof(XXX))]
public class XXXEditor : EventTriggerEditor
{
//This method is called every time Unity needs to show or update the
//inspector when you select a gameobject with an XXX component.
public override void OnInspectorGUI()
{
//Here the inspector will draw the default, generic inspector, which will show basically
//everything in a component, including the variables you want
DrawDefaultInspector ();
//And then we will draw the inspector for event types and events, which is the default behaviour.
base.OnInspectorGUI ();
}
}
I hope you get from this example you get the idea on how to customize the inspector further for your own needs.
Answer by Jason_Kalmatos · Jul 29, 2017 at 03:45 PM
Hi iBicha,
Thanks for your answer, as this is no longer relevant to me (I eventually used Debug mode), I have accepted your answer, but I would still try this method in my spare time!
Thank you for your help!
Regards, Jason
Your answer
![](https://koobas.hobune.stream/wayback/20220612130320im_/https://answers.unity.com/themes/thub/images/avi.jpg)