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
- Inspector window flickers when a selector is created using a Style Class List Section
- [iOS] "UnityBatchPlayerLoop()" causes a freeze in the iOS application when it is put to the background and brought back to the foreground
- "Perform Selected" of Shortcut Manager window does not perform the shortcut in some cases
- Crash on mono_get_hazardous_pointer when running Play Mode tests in a specific project
- [iOS] ‘확인’(Done) and '취소'(Cancel) text is displayed as '...' in the on-screen keyboard when the System preferred language is set to Korean
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