- Home /
Cannot convert serializedObject to float
I'm trying to create a custom inspector, so this is a short version of what I have:
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(SomeScript))]
public class SomeScriptEditor : Editor {
SerializedProperty someFloat;
void OnEnable() {
someFloat = serializedObject.FindProperty ("someFloat");
}
public override void OnInspectorGUI() {
EditorGUILayout.FloatField(someFloat, new GUIContent("Hello"));
}
}
But it doesn't work. It says it can't convert serialized property to float (EditorGUILayout.FloatField line). EditorGUILayout.PropertyField works, but why doesn't it work for me, but it does on the live training video?
Answer by Joyrider · Feb 09, 2015 at 10:21 AM
It has been a while since I wrote an editorscript but I think you need to use someFloat.floatValue to get the actual float value type needed in your FloatField.
EditorGUILayout.FloatField(someFloat.floatValue, new GUIContent("Hello"));
Your answer
Follow this Question
Related Questions
Property Drawers confusion 1 Answer
Custom editor: How to initialise a new array element? 1 Answer
Draw custom Property Field in Custom Editor 1 Answer
Why are the children of my Serialized Property not being drawn? 1 Answer
Custom Inspector: Using 'serializedObject' to access inherited members 1 Answer