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
0
Question by MAGTAR · Feb 06, 2020 at 02:20 PM · scriptableobjectpropertydrawer

ScriptableObject drawing error

Hi, i made a simple PropertyDrawer for a ScriptableObject

Code:

 [CustomPropertyDrawer(typeof(ScriptableObject), true)]
 public class ScriptableObjectDrawer : PropertyDrawer
 {
     // Cached scriptable object editor
     private Editor editor = null;
 
     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
     {
         Debug.Log("Drawing " + property.objectReferenceValue);
         Rect rectNorm = position;
 
         if (property.objectReferenceValue != null)
         {
             EditorGUI.LabelField(position, (property.objectReferenceValue as ScriptableObject).name);
         }
         else
         {
             //EditorGUI.PropertyField(position, property, true);
             //return;
             EditorGUI.PropertyField(position, property,true);
             return;
             //EditorGUI.LabelField(position, (property).displayName);
         }
 
         //position.height = EditorGUIUtility.singleLineHeight;
         // Draw foldout arrow
         property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none);
 
 
 
         // Draw foldout properties
         if (property.isExpanded)
         {
             // Make child fields be indented
             EditorGUI.indentLevel++;
             if ((property.objectReferenceValue == null))
             {
                 position.y += EditorGUIUtility.singleLineHeight;
                 position.height = EditorGUIUtility.singleLineHeight;
                 EditorGUI.PropertyField(position, property);
                 position = rectNorm;
             }
 
             if (property.objectReferenceValue != null)
             {
       
                 //(property.objectReferenceValue as ScriptableObject).name = EditorGUI.TextField(position, "name", (property.objectReferenceValue as ScriptableObject).name);
 
                 // Draw object properties
                 if (!editor)
                 {
                     Editor.CreateCachedEditor(property.objectReferenceValue, null, ref editor);
                 }
 
                 if (editor != null)
                 {
                     editor.OnInspectorGUI();
                 }
             }
 
             // Set indent back to what it was
             EditorGUI.indentLevel--;
         }
     }
 
 
 
 }

And i also made to Scriptable Object children: 1) GameRule :

 [CreateAssetMenu(fileName = "Game rule", menuName = "Game rules/game rule")]
 public class GameRule : ScriptableObject
 {
     [System.Serializable]
    public enum TriggerMode
     {
         //TBD
         OneToTrigger,
         AllToTrigger
     }
 
     [System.Serializable]
    public enum ActionMode
     {
         //TBD
         OneToDo,
         AllToDo
     }
 
     //Triggers : List<EventTrigger> TriggerMode : Enum Actions : List<GameAction> ActionMode : Enum
     //Maybe TriggerAction pair is better
     public TriggerMode triggerMode;
     public ActionMode actionMode;
 }

2) Level :

 [CreateAssetMenu(fileName = "levelSO", menuName = "Levels/Level")]
 public class Level : ScriptableObject
 {
     public string Name;
     public List<GameRule> Rules;
 }
 

Now , when i try to edit my SO level i get this error: ArgumentException: Getting control 1's position in a group with only 1 controls when doing repaint And it stops drawing...alt text

Can somebody pls explain me why this kind of error appears and is this a good practice to store SO inside others So. Thanks

снимок.png (12.1 kB)
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 MAGTAR · Feb 06, 2020 at 04:35 PM 0
Share

Even if i inherit Level from $$anonymous$$onoBehaviour a get the same error

avatar image MAGTAR · Feb 06, 2020 at 05:22 PM 0
Share

I also figured out that for some reason Layout event is not called at alll..... alt text Only repaint is called.... Is it my fault or it is a bug????

снимок.png (14.8 kB)

0 Replies

· Add your reply
  • Sort: 

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

122 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 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

PropertyDrawers not working with ScriptableObjects 1 Answer

Texture2D in ScriptableObject’s Property drawer experiences serious lag 3 Answers

Custom PropertyDrawer fails because my ScriptableObject property is not initialized in time 1 Answer

Invalid index 433 (size is zd) + ArgumentException: Getting control x's position in a group with only x controls when doing Repaint 1 Answer

EditorGUI.PrefixLabel returns a rect that doesn't line up with other content when a custom property drawer is used in an array. 2 Answers


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