- Home /
How to create a new SerializedProperty?
Recently Custom Editors in Unity caught my attention. Now I'm having a small problem.
I'm currently making a custom editor for a script with 5 properties. The first property is a color value, and will always be visible. The folowing enum should also be visible:
private enum MaterialType { Color, Pattern }
The other four properties should show up when you select the "Pattern" value. I'm using this code to show my enum:
MaterialType materialType = MaterialType.Color;
EditorGUILayout.PropertyField(materialType, new GUIContent("Color or pattern?"));
I'm getting this error: Cannot convert type 'TileObjectEditor.MaterialType' to 'UnityEditor.SerializedProperty'. I understand this error message, and my question is how to get the enum value into a SerializedProperty.
Note that the enum is not included in the base script itself. It is only needed in the editor script, so I can't use serObj.findProperty(...). I could solve this all by moving the enum to the base script, and just use serObj.findProperty("MaterialType"), but since MaterialType is unrelevant there, I'm looking for another way.
I managed to pull it off by using EditorGUILayout.EnumPopup, but this "popup" looks different than a PropertyField, and it doesn't have a label. And I'm curious about the alternatives.
Yep I was about to suggest you do just that - also interested!
Your answer
Follow this Question
Related Questions
serializedObject with EditorGUILayout.Popup in C# 1 Answer
Custom Editors : EnumFields, Proper Use Of 0 Answers
Custom editor struggle - "Invalid iteration - (You need to stop calling Next when it returns false)" 0 Answers
How to insert an element of specific type to a list as serializedProperty? 1 Answer