Hi,
In the Custom Editor I am trying to create an Asset that keeps a list of GameObject references together with some other attributes and store this in an Asset.
What works (please refer to the code further down below for details):
- The Asset file gets created fine.
- List items are added to the list via the AddItem() method and are visible in the inspector.
- New game objects are created in the hierarchy when object gets created via the AddItem() method.
What is not working:
- When selecting the asset in the Project window I can see the list in the inspector but for every single Game Object field I can see “Type mismatch” message. I would expect the “Test” name displayed just as for Monobehaviour scripts with GameObject properties.
- I cannot drag and drop game objects from the hierarchy to the inspector Game Object field. I would expect that I can drag and drop game objects from hierarchy just as for Monobehaviour scripts with GameObject properties.
- When clicking the dot next to the Game Object field in the Inspector I cannot see game objects that I can select from the pop-up window.
What am I doing wrong ? Can someone help please.
Data structures:
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class ScriptableObjectData {
public GameObject gameObject;
public Texture2D texRex;
public int ExecutionOrder;
}
[System.Serializable]
public class ScriptableObjectDataManager : ScriptableObject {
public List<ScriptableObjectData> scriptableObjectDataList = new new List<ScriptableObjectData>();
}
Method that adds an item to the list:
public class ScriptableObjectUser : EditorWindow {
(...)
void AddItem() {
ScriptableObjectData data = new ScriptableObjectData();
data.ExecutionOrder = ++counter;
data.gameObject = new GameObject("Test");
dataManager.scriptableObjectDataList.Add(data);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
(...)
}