Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 XGDragon · Jul 18, 2014 at 11:19 AM · arrayinspectornullreferenceexceptioneditorgui

Custom inspector, a multidimensional array of enums

Hello,

I've been searching everywhere for a solution, but cannot find it. I want to set parameters of some array as prefabs, and decided to use a custom inspector to edit these prefabs (rather than hard coding each individual class object.

Here's what I have:

 using UnityEngine;
 using System.Collections;
 
 public class Something : MonoBehaviour {
     
     public enum MovementTypes { None, Move, Jump};
     public MovementTypes[,] Movement = new MovementTypes[5,5];
     public string Name;
 }

And my Editor/ has

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 [CustomEditor(typeof(Something))]
 public class SomethingEditor : Editor {
     public override void OnInspectorGUI()
     {
         Something myS = (Something)target;
 
         myS.Name = EditorGUILayout.TextField("Type Name", myS.Name);
 
 
         for (int y = 0; y < 5; y++)
         {
             EditorGUILayout.BeginHorizontal ();
             for (int x = 0; x < 5; x++)
                 myS.Movement[x, y] = (Something.MovementTypes)EditorGUILayout.EnumPopup(myS.Movement[x, y]);
             EditorGUILayout.EndHorizontal ();
         }
 
     }
 }
 

This code graces me with the following errors:

  • NullReferenceException: Object reference not set to an instance of an object SomethingEditor.OnInspectorGUI () (at Assets/Editor/SomethingEditor.cs:17) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/InspectorWindow.cs:1124) UnityEditor.DockArea:OnGUI()

  • Unexpected top level layout group! Missing GUILayout.EndScrollView/EndVertical/EndHorizontal? UnityEditor.DockArea:OnGUI()

I've tried a bunch of things, and nothing works. I cannot edit the 5x5 array. The only work around I can fathom right now is to make 25 separate variables.......

Comment
Add comment · Show 2
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 polkovnikov.ph · Jul 18, 2014 at 01:57 PM 0
Share

You're creating a field before calling any of Begin* methods of EditorGUILayout.

avatar image XGDragon · Jul 18, 2014 at 02:36 PM 0
Share

Are you referring to

myS.Name = EditorGUILayout.TextField("Type Name", myS.Name);

Because that line works fine. The xy loop does not.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by smallbit · Jul 18, 2014 at 12:17 PM

I cannot help with custom editor, but you can setup array of arrays (two dimensional array) of enums in the inspector in the following way.

 [System.Serializable]
     public class class1{
         public enum myEnum {one,two,three};
         public myEnum[] row;
     }
     public class1[] array;

In the inspector you get this :

![alt text][1]


inspector.png (12.7 kB)
inspector.png (12.7 kB)
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 XGDragon · Jul 18, 2014 at 01:55 PM 0
Share

Thanks for the suggestion, but I know this is possible. However, I absolutely need the grid layout or it will be very complicated for me.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Array values not being initialised unless the object with the (Player) script is selected in the inspector whilst the game is on 1 Answer

Null Reference using IMGUIContainer and array fields 0 Answers

Property Drawer and Children 3 Answers

[SOLVED]How to use attributes from array of custom class instances? 1 Answer

How to change array orders in the inspector 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