- Home /
Question by
harveyhb · Sep 18, 2014 at 02:51 PM ·
custom editorcustom inspector
Custom Editor - Loosing prefab connections at runtime
I can drag a prefab to the empty gameobject slot in inspector fine, but once I hit play the connection is lost.
My editor script looks like this
[CustomEditor(typeof(IglooCameraController))]
[CanEditMultipleObjects]
public class IglooCameraControllerEditor : Editor {
IglooCameraController cameraObject;
public void OnEnable(){
cameraObject= (IglooCameraController)GameObject.FindObjectOfType(typeof(IglooCameraController));
}
public override void OnInspectorGUI(){
serializedObject.Update();
cameraObject.cameraPrefab= EditorGUILayout.ObjectField("Camera Prefab",cameraObject.cameraPrefab, typeof(GameObject),true) as GameObject;
cameraObject.setVlaues ();
}
}
And the IglooCameraController looks like this (I've taken all irrelevant code out)
public class IglooCameraController : MonoBehaviour {
public GameObject cameraPrefab;
}
Comment
Answer by harveyhb · Sep 18, 2014 at 03:15 PM
Fixed it. For anyone interested I was missing a cast here. cameraObject.cameraPrefab= (GameObject) EditorGUILayout.ObjectField("Camera Prefab",cameraObject.cameraPrefab, typeof(GameObject),true) as GameObject;