• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Olinus · Sep 15, 2017 at 09:27 PM · scriptableobjectcustom editorassetdatabaseeditor window

"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. alt text

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


error.png (29.2 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Olinus · Sep 17, 2017 at 10:25 AM 0
Share

Hello ? This is simple stuff to reproduce.

Can anyone help me please ?

Many thanks.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Sep 17, 2017 at 10:39 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Olinus · Sep 17, 2017 at 02:00 PM 1
Share

... and that is why I could only see "Assets" tab and not any other Game Objects after pressing circle next to Game Objects.

But when I add Animation type property to my data type I could see the list of available animations and choose one of them to be stored in my Asset.

Got it ! Many thanks !

avatar image
1

Answer by meebou · May 08 at 12:06 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

74 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Calling a custom inspector from an editor window of an instance of a class 1 Answer

Importing and using custom assets 0 Answers

Generic List In Custom Editor Window 1 Answer

Getting Reference to Asset without calling LoadAsset 0 Answers

Display List of Objects in Editor Window 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges