I am making a custom inspector, how do I make a field for say a sprite?
An object field:
I am using this for a sprite and whenever I try to assign it it gives me this error.
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.EditorGUI.ValidateObjectFieldAssignment (UnityEngine.Object references, System.Type objType, UnityEditor.SerializedProperty property) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/EditorGUI.cs:2454)
UnityEditor.EditorGUI.DoObjectField (Rect position, Rect dropRect, Int32 id, UnityEngine.Object obj, System.Type objType, UnityEditor.SerializedProperty property, UnityEditor.ObjectFieldValidator validator, Boolean allowSceneObjects, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/GUI/ObjectField.cs:44)
UnityEditor.EditorGUI.DoObjectField (Rect position, Rect dropRect, Int32 id, UnityEngine.Object obj, System.Type objType, UnityEditor.SerializedProperty property, UnityEditor.ObjectFieldValidator validator, Boolean allowSceneObjects) (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/GUI/ObjectField.cs:12)
UnityEditor.EditorGUI.ObjectField (Rect position, UnityEngine.Object obj, System.Type objType, Boolean allowSceneObjects) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/EditorGUI.cs:2380)
CourseBlockEdit.OnInspectorGUI () (at Assets/Editor/CourseBlockEdit.cs:20)
UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor editors, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/Inspector/InspectorWindow.cs:850)
UnityEditor.DockArea:OnGUI()
Edit: if it matters I am not using GUILayout.objectfeild() I am using GUI.objectFeild()