Help Simple adding a GameObject to an ObjectField()
For some reason when I try to drag and drop my prefab into the object field it doesn't stick. I'm not sure where I'm going wrong. Maybe it's just a simple mistake. Thanks in advance.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class FracObject : MonoBehaviour {
public GameObject go;
}
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(FracObject))]
public class FracOjectEditor : Editor {
SerializedProperty goprop;
private void OnEnable()
{
goprop = serializedObject.FindProperty("go");
}
public override void OnInspectorGUI()
{
goprop.objectReferenceValue = EditorGUILayout.ObjectField(new GUIContent("Source", "Add object to fracture"), goprop.objectReferenceValue, typeof(GameObject), false);
}
}
Answer by tsdavs · Jun 15, 2017 at 10:18 AM
Solved this one with help from @baste :
http://answers.unity3d.com/questions/847584/custom-editor-object-field-getting-serialized-obje.html
I was missing this line after objectreferencevalue();
serializedObject.ApplyModifiedProperties();
Appears to work as it should now
Thank-you so much for updating your post with the correct answer! I've been trying to get object fields to work for hours now and finally got it working thanks to this post!!!
Your answer
Follow this Question
Related Questions
Set content of ObjectField from Editor Script 0 Answers
Object field in the scene view - Custom Editor Script 0 Answers
Custom Editor slider not working inside if statement 0 Answers
NullReferenceException: Object reference not set to an instance of an object (int[,]) 1 Answer
Recently updated Unity 5 and now my project Scripts with not communicate 0 Answers