Search Issue Tracker
By Design
Votes
3
Found in
2019.4
2019.4.8f1
2020.1
2020.2
Issue ID
1277326
Regression
No
Public Variables from Custom public class is not visible in the Inspector when it is declared in non-MonoBehaviour Class
Steps to reproduce:
1. Open the attached project "Case_1277326"
2. Open "SampleScene"
3. In the Hierarchy window Expand select Canvas->GameObject
4. In the Inspector window notice that there is not "onItemChanged" class
Expected results: public class "onItemChanged" is visible in the Inspector window
Actual results: public class "onItemChanged" is not visible in the Inspector window
Reproducible with: 2019.4.9f1, 2020.1.6f1, 2020.2.0b2
Unable to test with: Due to classes derived not from Monobehaviour are not allowed on GameObjects
Note:
-If the Script is imported to the Project with MonoBehaviour main class and then changed to ScrollRect it will not reproduce the issue but could throw errors, then reimporting it fixes the errors but the issue starts to occurs
-Screenshots of expected and actual are below
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Opening Terrain Prefab in Prefab Editing Mode throws "NullReferenceException" error
- [Search] Dragging query pills put them behind the search text field
- A CustomPropertyDrawer that returns a PropertyField for a property named the same as a child field will not render all child fields
- Graphics Settings shows default values instead of the real values in the Rendering Debugger when Volume.profile is assigned via script
- Deleting multiple Tags throws “NullReferenceException”, and "Retrieving array element that was out of bounds" errors when holding the Enter key
Resolution Note:
This is how inspector framework works.
In this specific case, MonoBehaviour inherits from ScrollRect and because of that Inspector appearance/drawing is controlled by ScrollRectEditor.
You can draw your custom properties by extending ScrollRectEditor:
[CustomEditor(typeof(NewBehaviourScript))]
public class NewBehaviourScriptEditor : ScrollRectEditor
{
private SerializedProperty onItemChangedProp;
protected override void OnEnable()
{
base.OnEnable();
onItemChangedProp = serializedObject.FindProperty("onItemChanged");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.PropertyField(onItemChangedProp);
serializedObject.ApplyModifiedProperties();
}
}
You can find more information on creating custom editors in here: https://docs.unity3d.com/Manual/editor-CustomEditors.html