- Home /
Use PropertyDrawer with System.Reflection
Hey I'm trying to write a PropertyDrawer for a Serialized Class that uses Members of System.Reflection like MethodInfo/ParameterInfo/... but if i try for example:
SerializedProperty mParam = property.FindPropertyRelative( "m_MethodParams" );
if(mParam.arraySize > 0)
EditorGUI.PropertyField( new Rect( position.x + position.width * 0.75f, position.y + 55, position.width * 0.25f, 15 ),mParam , true );
I get a null reference exception? So is property.FindPropertyRelative
only usable with object that inherit from UnityEngine.Object
?
Answer by Bunny83 · Apr 29, 2018 at 11:15 AM
A PropertyDrawer, SerializedProperties and SerializedObject is only valid for things that can actually be serialized by Unity's serializer. The MethodInfo, ParameterInfo and even the System.Type class can not be serialized by Unity. Have a look at the script serialization page
ps: If you need a serializable $$anonymous$$ethodInfo / System.Type version I've created a Serializable$$anonymous$$ethodInfo and SerializableType (which is required by the Serializable$$anonymous$$ethodInfo). However those do not work with Unity's SerializedProperty or SerializedObject classes as they can only access the actual serialized data which is just a byte array in the case of the SerializableType.
It was quite some time ago when i've written those two classes. However as far as i remember the SerializableType supports generic types while the $$anonymous$$ethodInfo does support methods of a generic type but not generic methods (like GetComponent<T>()
for example).
thanks! So implementing ISerializationCallbackReceiver
can make any class usable for a PropertyDrawer?