Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 cow_co · Feb 16, 2016 at 12:53 PM · editoreditor-scriptingscriptableobjecteditorguilayoutobjectfield

EditorGUILayout.ObjectField does not allow me to select a script.

I am trying to make a custom editor window to make a node-editor for the AI in my game. Currently the nodes themselves are displaying nicely (with one or two little bugs), but the object fields I have on each node aren't working. I have a base class script called "State" which is meant to represent an AI State:

 [System.Serializable]
     public class State : ScriptableObject
     {
         public StateIDs _id;
         [SerializeField]private List<TransitionBase> _availableTransitions;
         //some irrelevent code
     }

and then the node is a class which looks like this:

 namespace Assets._Custom._Scripts._Editor
 {
     [System.Serializable]
     public class Node
     {
         public int _id;
         public Rect _box;
         public State _state;
         public FSMNodeEditor _owner;
         
         public Node(int ID, Rect rect, State initState, FSMNodeEditor owner)
         {
             _id = ID;
             _box = rect;
             _state = initState;
             _owner = owner;
         }
             
         public Node(int ID, Rect rect, FSMNodeEditor owner)
         {
             _id = ID;
             _box = rect;    
             _state = (State)ScriptableObject.CreateInstance(typeof(State));
             _owner = owner;
         }
             
         public Node(Rect rect, FSMNodeEditor owner)
         {
             _id = 0;
             _box = rect;
             _state = (State)ScriptableObject.CreateInstance(typeof(State));
             _owner = owner;
         }
             
         public Node(FSMNodeEditor owner)
         {
             _id = 0;
             _box = new Rect();
             _state = (State)ScriptableObject.CreateInstance(typeof(State));
             _owner = owner;
         }
         
         public void DrawNode(int id)
         {
             EditorGUILayout.ObjectField(_state, typeof(State), false);
             
             if(id != _id)
             {
                 Debug.LogError("Given ID and Node ID do not match");
                 
                 return;
             }
             
             if(GUILayout.Button("Join Node"))
             {
                 _owner.JoinNode(id);
             }
             
             if(GUILayout.Button("Delete Node"))
             {
                 _owner.NodeDeleted(id);
             }
 
             GUI.DragWindow();
         }
     }
 }

As you can see, I am trying to use EditorGUILayout.ObjectField to enable me to choose a State to edit in that Node. Problem is, when I create a node in the editor window and click on the button on the object field, no States pop up. There is nothing to choose. I tried making a "TestState" derived from the base State class, but no luck. It just says "None" when I try to choose a State. I even tried dragging TestState onto the object field, but it didn't let me put it in there.

So what is going wrong? Is it because State is a ScriptableObject?

Thank you for any help.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Meatgrind · Oct 25, 2016 at 08:06 AM

Seems that the ObjectField only takes some basic types for filtering the AssetDataBase: if I use typeof(MyOwnComponentClass) it will indeed display "None" and when clicking the small circle, will display an ObjectSelector Window with an empty, unusable list.

But it will accept typeof(GameObject) or some other Unity asset types, and will show a filtered list of Prefabs, AudioClips, etc. if needed. I'd wish it had more usability for scripts.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

why I Cant Add Multiple Objects to the "Object Field" in Editor Window? 3 Answers

Editor GUI object field stops working 0 Answers

Stop a MonoBehavior from being addable as a script? 0 Answers

Drawing position handle from ScriptableObject editor. 2 Answers

Get list of all "Action" classes 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges