"Type mismatch" in Inspector for GameObject type in asset file

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):

  1. The Asset file gets created fine.
  2. List items are added to the list via the AddItem() method and are visible in the inspector.
  3. New game objects are created in the hierarchy when object gets created via the AddItem() method.

What is not working:

  1. 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.
  2. 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.
  3. 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();
        }
    (...)
}

Obviously an asset stored in the project can’t reference anything that is located in a scene. Everything that is located in a scene is only available when the scene is loaded / active. Assets are presistent across the whole project and they can only reference other assets in the project.

The reverse is possible. Objects in the scene can reference other objects in the same scene or any asset stored in the project as assets are always available unlike objects in a scene.

If you want some sort of manager that holds references to objects in the scene you have to create it as MonoBehaviour an attach it to an object in the same scene.

came here to the same problem.everybody says DONT USE SINGLETON…use SCRIPTABLE OBJECTS…and now nothing works like it has worked before :frowning: so hello singleton again :wink:

Hello ? This is simple stuff to reproduce.

Can anyone help me please ?

Many thanks.

make a prefab of object you have to put in "type mis match " and put prefab their