- Home /
Question by
toblorone · Mar 21, 2018 at 08:12 PM ·
editorscriptableobjectcustom editor
Drag from custom editor ObjectField
Hi, I'm looking for a way to drag a reference from an object to another component using a custom editor. My code looks more or less like this:
using System;
using UnityEngine;
using UnityEditor
class Data : ScriptableObject {
public int Foo = 1;
}
[ExecuteInEditor]
class Component : MonoBehaviour {
public Data data;
public void Awake (){
if (data != null) data = ScriptableObject.CreateInstance<Data>();
}
[CustomEditor(typeof(Component))]
public class ComponentEditor : Editor {
public override void OnInspectorGUI () {
var comp = (Component)target;
comp.data = EditorGUILayout.ObjectField("Data", comp.data, typeof(Data), true);
}
}
I'd like to be able to drag from the Data
field from this component's inspector to another component. Is this possible?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612155104im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why isn't my CustomEditor's OnInspectorGUI() running? 1 Answer
Serializing a ScriptableObject without creating an asset for it? 2 Answers
ScriptableObject not saving data to asset 2 Answers
Unity inspector scripting - scriptable objects - card game 0 Answers
Custom editor script for folders? 1 Answer