Fields disappearing when inheriting from Standard UI Menu Panel?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
alexlol
Posts: 35
Joined: Sat Nov 07, 2020 8:20 am

Fields disappearing when inheriting from Standard UI Menu Panel?

Post by alexlol »

Hi,

I've extended the Standard UI Menu Panel class to add a couple of custom functions. Included in this new script are a few public fields to assign, including a gameobject, transform and audio source.

However, when I inherit from Standard UI Menu Panel, all of my public fields from the derived script disappear, leaving only the inherited ones. If I remove the inheritance and inherit from Monobehaviour, my fields reappear. I'm not getting any warnings about hiding inherited members.

I can't seem to figure out the problem - is this standard behaviour or something specific to Dialogue System? Would really appreciate a pointer in the right direction! Thanks.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Fields disappearing when inheriting from Standard UI Menu Panel?

Post by Tony Li »

Hi,

Are you talking about your custom fields not appearing in the inspector?

If so, this is because StandardUIMenuPanel uses a custom inspector script named StandardUIMenuPanelEditor. You can subclass it to show your custom fields. Create a new script in any folder named Editor, such as:

CustomMenuPanelEditor.cs

Code: Select all

using UnityEngine;
using UnityEditor;
using PixelCrushers.DialogueSystem;

[CustomEditor(typeof(CustomMenuPanel))]
public class CustomMenuPanelEditor : StandardUIMenuPanelEditor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        
        serializedObject.Update();
        
        // Your code here to show your custom fields. Example:
        EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(CustomMenuPanel.myCustomField1)), true);
        EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(CustomMenuPanel.myCustomField2)), true);
        
        serializedObject.ApplyModifiedProperties();
    }
}
alexlol
Posts: 35
Joined: Sat Nov 07, 2020 8:20 am

Re: Fields disappearing when inheriting from Standard UI Menu Panel?

Post by alexlol »

I'm referring to publicly exposing objects so I can assign them in the inspector - is that the same thing? Sorry, I'm a bit new to inspector stuff :)
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Fields disappearing when inheriting from Standard UI Menu Panel?

Post by Tony Li »

Yes, that's the same thing. For example, say you've made a subclass like this:

Code: Select all

public class CustomMenuPanel : StandardUIMenuPanel
{
    public int numMenusShown; // Counts # of times ShowResponses is called this play session.
    
    public override void ShowResponses(Subtitle subtitle, Response[] responses, Transform target)
    {
        base.ShowResponses(subtitle, responses, target);
        numMenusShown++;
    }
}
Then you'd need to create an Editor script like this to show the "numMenusShown" variable:

Code: Select all

using UnityEngine;
using UnityEditor;
using PixelCrushers.DialogueSystem;

[CustomEditor(typeof(CustomMenuPanel))]
public class CustomMenuPanelEditor : StandardUIMenuPanelEditor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        
        serializedObject.Update();
        
        // Show the numMenusShown field:
        EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(CustomMenuPanel.numMenusShown)), true);
        
        serializedObject.ApplyModifiedProperties();
    }
}
alexlol
Posts: 35
Joined: Sat Nov 07, 2020 8:20 am

Re: Fields disappearing when inheriting from Standard UI Menu Panel?

Post by alexlol »

Understood, thanks!
Post Reply