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 JulesPomme · Aug 28, 2015 at 12:08 PM · c#custom editor

CustomPropertyDrawer property set to null when in List

Hi all. I'm making a basic 2D fighting game, using Unity 5. I have a class called SpecialHitActivator, that tracks the inputs of a player, detects if a special hit should be activated, and eventually activate it. This class have a public list of SpecialHit objects, SpecialHit being a nested class, with an AnimationClip, and a list of strings for its possible input combinations. The list of SpecialHit is determined by a text file I provide in the editor, through a TextAsset object.

I want to make a custom inspector to represent all that data. So far I have done a CustomEditor for my SpecialHitActivator, and a CustomPropertyDrawer for my nested class SpecialHit.

Here is a picture of what it looks like : alt text

Basically, my text file contains all the special hit names + combinations for a specific character. As soon as I drag and drop a file in my TextAsset field, the list of special hits is automatically updated, visible but non-editable, so I just have to provide the animation clips (next step is to automate the filling of this field too, provided that the name of the hit and its corresponding animation are equal).

My problem is the following: every time I fold in or fold out any of the lists here (Special Hit List, Directional Jump Kick or Hadouken), all the animation clips are reset to none! I can't figure out why. Here is the code of my custom editor :

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 using UnityEditor.Animations;
 
 [CustomEditor(typeof(SpecialHitActivator))]
 public class SpecialHitActivatorEditor : Editor
 {
     public override void OnInspectorGUI ()
     {
         SpecialHitActivator specialHitActivator = (SpecialHitActivator)target;
 
         serializedObject.Update ();
         EditorGUI.BeginChangeCheck ();
 
         //TEXTASSET
         specialHitActivator.specialHitListFile = (TextAsset)EditorGUILayout.ObjectField ("Special Hit List File", specialHitActivator.specialHitListFile, typeof(TextAsset), false);
         //ANIMATOR CONTROLLER
         specialHitActivator.animatorController = (AnimatorController)EditorGUILayout.ObjectField ("Animator Controller", specialHitActivator.animatorController, typeof(AnimatorController), false);
         //SPECIAL HIT LIST
         SerializedProperty specialHitListProp = serializedObject.FindProperty ("specialHitList");
         EditorGUILayout.PropertyField (specialHitListProp);
         if (specialHitListProp.isExpanded) {
             int oldIndentLevel = EditorGUI.indentLevel;
             EditorGUILayout.LabelField ("Size: " + specialHitListProp.arraySize);
             EditorGUI.indentLevel += 1;
             for (int i = 0; i < specialHitListProp.arraySize; i++) {
                 EditorGUILayout.PropertyField (specialHitListProp.GetArrayElementAtIndex (i));
             }
             EditorGUI.indentLevel = oldIndentLevel;
         }
 
         if (EditorGUI.EndChangeCheck ()) {
             specialHitActivator.ParseFile ();
             serializedObject.ApplyModifiedProperties ();
         }
     }
 }

and here is the code of my custom property drawer :

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 [CustomPropertyDrawer(typeof(SpecialHitActivator.SpecialHit))]
 public class SpecialHitDrawer : PropertyDrawer
 {
 
     SerializedProperty combinationListProp;
     SerializedProperty clipProp;
 
     public override float GetPropertyHeight (SerializedProperty property, GUIContent label)
     {
         combinationListProp = property.FindPropertyRelative ("combinationList");
         clipProp = property.FindPropertyRelative ("clip");
         float height = 16f;
         if (combinationListProp.isExpanded) {
             height += combinationListProp.arraySize * 18;
         }
         return height;
     }
 
     public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
     {
         EditorGUI.BeginProperty (position, label, property);
 
         //FOLDOUT
         float foldoutPercentWitdh = 0.35f;
         Rect foldoutPosition = new Rect (position.x, position.y, position.width * foldoutPercentWitdh, 16f);
         combinationListProp.isExpanded = EditorGUI.Foldout (foldoutPosition, combinationListProp.isExpanded, label);
 
         //ANIMATION CLIP
         float labelWidth = EditorGUIUtility.labelWidth;
         EditorGUIUtility.labelWidth = 50;
         Rect clipPosition = new Rect (position.x + position.width * foldoutPercentWitdh, position.y, position.width * (1 - foldoutPercentWitdh), 16f);
         EditorGUI.PropertyField (clipPosition, clipProp, new GUIContent ("Clip"));
         EditorGUIUtility.labelWidth = labelWidth;
 
         //HIT COMBINATIONS
         int oldIndentLevel = EditorGUI.indentLevel;
         EditorGUI.indentLevel += 1;
         if (combinationListProp.isExpanded) {
             for (int i = 0; i < combinationListProp.arraySize; i++) {
                 Rect pos = position;
                 pos.y += (i + 1) * 18f;
                 pos.height = 16f;
                 SerializedProperty combinationProp = combinationListProp.GetArrayElementAtIndex (i);
                 EditorGUI.LabelField (pos, combinationProp.stringValue);
             }
         }
         EditorGUI.indentLevel = oldIndentLevel;
 
         EditorGUI.EndProperty ();
     }
 }

Does anyone have a clue on what's happening here? Thanks a lot!

specialhitactivator-inspector.png (14.8 kB)
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
0
Best Answer

Answer by JulesPomme · Aug 28, 2015 at 01:45 PM

Ok...I've been looking for 3 days for this, and I just realized that my method SpecialHitActivator.ParseFile() was bugged...I deeply apologize for this useless topic...

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

Custom Editor value change 0 Answers

Override Transform Inspector for specific GameObjects 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