Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by nuclear237 · Aug 03, 2020 at 10:10 AM · custom editoreditorguieditorguilayout

Custom Editor] FindProperty can't find a specific property!,CustomEditor] FindProperty can't find specific object

Hi. I faced really weird problem when i customize editor.

alt text In this script capture, BuffElements buffElementsMoveSlow is missing! all public variables are displayed except BuffElements. Looks all conditions are same but I can't guess why only that variable is not displayed on the editor. please help!

here' s orginal script:

 public class Tower : MonoBehaviour
 {
     //-----------------------------------------------------------
     // Inspectors are controlled by TurretEditor
     //-----------------------------------------------------------
     public enum ProjectileType
     {
         Bullet = 0,
         Laser = 1
     }
 
     private Transform targetTransform;
     private Enemy targetEnemy;
 
     //[Header("General")]
     public float range = 5f;
 
     //[Header("Projectile Type")]
     public ProjectileType projectileType;
 
     //[Header("Projectile Type : Bullet")]
     private float fireCountdown = 0;
     public GameObject bulletPrefab;
     public float fireRate = 0.2f;
 
 
     //[Header("Projectile Type : Laser")]
     public int damageOverTime = 30;
     public float slowPercent = 0.5f;
     public LineRenderer lineRenderer;
     public ParticleSystem laserBeamImpactEffect;
     public Light laserBeamImpactLight;
     public BuffElements buffElementsMoveSlow;
     private Coroutine laserDubffCoroutin;
     //[Header("Unity Setup fields")]
     public string enemyTag = "Enemy";
     public Transform partToRotate;
     public Transform firePoint;
     public float turnSpeed = 10f;
     
     ////////////////////////////////////////////////////////////////
     
     void Start()
     {
         InvokeRepeating("UpdateTarget", 0f, 0.5f);
     }
 .....
 }

This is custom editor script :

 using UnityEditor;
 
 public enum ProjectileType
 {
     
     Bullet = 0,
     Laser = 1
 }
 
 [CanEditMultipleObjects]
 [CustomEditor (typeof(Tower))]
 public class TowerEditor : Editor
 {
     float rangeProperty;
     //[Header("Projectile Type")]
     SerializedProperty projectileTypeProperty;
     //[Header("Projectile Type : Bullet")]
     float fireRateProperty;
     SerializedProperty bulletPrefabProperty;
     //[Header("Projectile Type : Laser")]
     int damageOverTimeProperty;
     float slowPercentProperty;
     SerializedProperty lineRendererProperty;
     SerializedProperty laserBeamImapctEffectProperty;
     SerializedProperty laserBeamImpactLightProperty;
     SerializedProperty buffElementsMoveSlowProperty;
     
     //[Header("Unity Setup fields")]
     string enemyTagProperty;
     SerializedProperty partToRotateProperty;
     SerializedProperty firePointProperty;
     float turnSpeedProperty;    
 
     private void OnEnable()
     {
         rangeProperty = serializedObject.FindProperty("range").floatValue;
         //[Header("Projectile Type : Bullet")]
         fireRateProperty = serializedObject.FindProperty("fireRate").floatValue;
         bulletPrefabProperty = serializedObject.FindProperty("bulletPrefab");
         //[Header("Projectile Type : Laser")]
         damageOverTimeProperty = serializedObject.FindProperty("damageOverTime").intValue;
         slowPercentProperty = serializedObject.FindProperty("slowPercent").floatValue;
         lineRendererProperty = serializedObject.FindProperty("lineRenderer");
         laserBeamImapctEffectProperty = serializedObject.FindProperty("laserBeamImapctEffect");
         laserBeamImpactLightProperty = serializedObject.FindProperty("laserBeamImpactLight");
         buffElementsMoveSlowProperty = serializedObject.FindProperty("buffElementsMoveSlow");
         //[Header("Unity Setup fields")]
         enemyTagProperty = serializedObject.FindProperty("enemyTag").stringValue;
         partToRotateProperty = serializedObject.FindProperty("partToRotate");
         firePointProperty = serializedObject.FindProperty("firePoint");
         turnSpeedProperty = serializedObject.FindProperty("turnSpeed").floatValue;
 
     }
     
     public override void OnInspectorGUI()
     {
         
         serializedObject.Update();
         
         EditorGUILayout.LabelField("[General]");
         EditorGUILayout.FloatField("Explosion Range by :", rangeProperty);
 
         EditorGUILayout.LabelField("[Projectile Type]");
 

         projectileTypeProperty = serializedObject.FindProperty("projectileType");
         EditorGUILayout.PropertyField(projectileTypeProperty);
         ProjectileType projectileType = (ProjectileType)projectileTypeProperty.enumValueIndex;
         
         /////////////////////////////////////////////////////////////////////////////////////////////////////////
 
         switch (projectileType)
         {
             // projectile Bullet 
             case ProjectileType.Bullet:
                 // tower using Bullet 
                 EditorGUILayout.LabelField("[Projectile : Bullet]");
 
                 EditorGUILayout.FloatField("Fire rate (Speed) by :", fireRateProperty);
                 if (bulletPrefabProperty != null)
                     EditorGUILayout.ObjectField(bulletPrefabProperty);
 
                 break;
             // projectile Laser
             case ProjectileType.Laser:
                 // tower using laser
                 EditorGUILayout.LabelField("[Projectile : Laser]");
                 EditorGUILayout.LabelField("Damage Over Time by: ");
                 EditorGUILayout.IntField(" ", damageOverTimeProperty); 
                 EditorGUILayout.FloatField("Slow down by: ", slowPercentProperty);
                 if (lineRendererProperty != null)
                     EditorGUILayout.ObjectField(lineRendererProperty);
                 if (laserBeamImapctEffectProperty != null)
                     EditorGUILayout.ObjectField(laserBeamImapctEffectProperty);
                 if (laserBeamImpactLightProperty != null)
                     EditorGUILayout.ObjectField(laserBeamImpactLightProperty);
                 if (buffElementsMoveSlowProperty != null)
                     EditorGUILayout.ObjectField(buffElementsMoveSlowProperty);  
                 break;
         }
         EditorGUILayout.TextField("Target tag string", enemyTagProperty);
         EditorGUILayout.ObjectField(partToRotateProperty);
         EditorGUILayout.ObjectField(firePointProperty);
         EditorGUILayout.FloatField("Turn speed by: ", turnSpeedProperty);
 
         serializedObject.ApplyModifiedProperties();
         
     }
 }


,Hi. I faced really weird problem when i customize editor. alt text In this script capture, BuffElements buffElementsMoveSlow is missing! all public variables are displayed except BuffElements. Looks all conditions are same but I can't guess why only that variable is not displayed on the editor. please help!

here' s orginal script:

 public class Tower : MonoBehaviour
 {
     //-----------------------------------------------------------
     // Inspectors are controlled by TurretEditor
     //-----------------------------------------------------------
     public enum ProjectileType
     {
         Bullet = 0,
         Laser = 1
     }
 
     private Transform targetTransform;
     private Enemy targetEnemy;
 
     //[Header("General")]
     public float range = 5f;
 
     //[Header("Projectile Type")]
     public ProjectileType projectileType;
 
     //[Header("Projectile Type : Bullet")]
     private float fireCountdown = 0;
     public GameObject bulletPrefab;
     public float fireRate = 0.2f;
 
 
     //[Header("Projectile Type : Laser")]
     public int damageOverTime = 30;
     public float slowPercent = 0.5f;
     public LineRenderer lineRenderer;
     public ParticleSystem laserBeamImpactEffect;
     public Light laserBeamImpactLight;
     public BuffElements buffElementsMoveSlow;
     private Coroutine laserDubffCoroutin;
     //[Header("Unity Setup fields")]
     public string enemyTag = "Enemy";
     public Transform partToRotate;
     public Transform firePoint;
     public float turnSpeed = 10f;
     
     ////////////////////////////////////////////////////////////////
     
     void Start()
     {
         InvokeRepeating("UpdateTarget", 0f, 0.5f);
     }
 .....
 }

This is custom editor script :

 using UnityEditor;
 
 public enum ProjectileType
 {
     
     Bullet = 0,
     Laser = 1
 }
 
 [CanEditMultipleObjects]
 [CustomEditor (typeof(Tower))]
 public class TowerEditor : Editor
 {
     float rangeProperty;
     //[Header("Projectile Type")]
     SerializedProperty projectileTypeProperty;
     //[Header("Projectile Type : Bullet")]
     float fireRateProperty;
     SerializedProperty bulletPrefabProperty;
     //[Header("Projectile Type : Laser")]
     int damageOverTimeProperty;
     float slowPercentProperty;
     SerializedProperty lineRendererProperty;
     SerializedProperty laserBeamImapctEffectProperty;
     SerializedProperty laserBeamImpactLightProperty;
     SerializedProperty buffElementsMoveSlowProperty;
     
     //[Header("Unity Setup fields")]
     string enemyTagProperty;
     SerializedProperty partToRotateProperty;
     SerializedProperty firePointProperty;
     float turnSpeedProperty;    
 
     private void OnEnable()
     {
         rangeProperty = serializedObject.FindProperty("range").floatValue;
         //[Header("Projectile Type : Bullet")]
         fireRateProperty = serializedObject.FindProperty("fireRate").floatValue;
         bulletPrefabProperty = serializedObject.FindProperty("bulletPrefab");
         //[Header("Projectile Type : Laser")]
         damageOverTimeProperty = serializedObject.FindProperty("damageOverTime").intValue;
         slowPercentProperty = serializedObject.FindProperty("slowPercent").floatValue;
         lineRendererProperty = serializedObject.FindProperty("lineRenderer");
         laserBeamImapctEffectProperty = serializedObject.FindProperty("laserBeamImapctEffect");
         laserBeamImpactLightProperty = serializedObject.FindProperty("laserBeamImpactLight");
         buffElementsMoveSlowProperty = serializedObject.FindProperty("buffElementsMoveSlow");
         //[Header("Unity Setup fields")]
         enemyTagProperty = serializedObject.FindProperty("enemyTag").stringValue;
         partToRotateProperty = serializedObject.FindProperty("partToRotate");
         firePointProperty = serializedObject.FindProperty("firePoint");
         turnSpeedProperty = serializedObject.FindProperty("turnSpeed").floatValue;
 
     }
     
     public override void OnInspectorGUI()
     {
         
         serializedObject.Update();
         
         EditorGUILayout.LabelField("[General]");
         EditorGUILayout.FloatField("Explosion Range by :", rangeProperty);
 
         EditorGUILayout.LabelField("[Projectile Type]");
 

         projectileTypeProperty = serializedObject.FindProperty("projectileType");
         EditorGUILayout.PropertyField(projectileTypeProperty);
         ProjectileType projectileType = (ProjectileType)projectileTypeProperty.enumValueIndex;
         
         /////////////////////////////////////////////////////////////////////////////////////////////////////////
 
         switch (projectileType)
         {
             // projectile Bullet 
             case ProjectileType.Bullet:
                 // tower using Bullet 
                 EditorGUILayout.LabelField("[Projectile : Bullet]");
 
                 EditorGUILayout.FloatField("Fire rate (Speed) by :", fireRateProperty);
                 if (bulletPrefabProperty != null)
                     EditorGUILayout.ObjectField(bulletPrefabProperty);
 
                 break;
             // projectile Laser
             case ProjectileType.Laser:
                 // tower using laser
                 EditorGUILayout.LabelField("[Projectile : Laser]");
                 EditorGUILayout.LabelField("Damage Over Time by: ");
                 EditorGUILayout.IntField(" ", damageOverTimeProperty); 
                 EditorGUILayout.FloatField("Slow down by: ", slowPercentProperty);
                 if (lineRendererProperty != null)
                     EditorGUILayout.ObjectField(lineRendererProperty);
                 if (laserBeamImapctEffectProperty != null)
                     EditorGUILayout.ObjectField(laserBeamImapctEffectProperty);
                 if (laserBeamImpactLightProperty != null)
                     EditorGUILayout.ObjectField(laserBeamImpactLightProperty);
                 if (buffElementsMoveSlowProperty != null)
                     EditorGUILayout.ObjectField(buffElementsMoveSlowProperty);  
                 break;
         }
         EditorGUILayout.TextField("Target tag string", enemyTagProperty);
         EditorGUILayout.ObjectField(partToRotateProperty);
         EditorGUILayout.ObjectField(firePointProperty);
         EditorGUILayout.FloatField("Turn speed by: ", turnSpeedProperty);
 
         serializedObject.ApplyModifiedProperties();
         
     }
 }


2020-08-03-16-41-19-project-samplescene-pc-mac-lin.png (26.0 kB)
2020-08-03-16-41-19-project-samplescene-pc-mac-lin.png (26.0 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

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

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

Adding space() to BeginHorizontal() causes extra vertical spacing after certain amount. 1 Answer

EditorGUILayout.ObjectField on a ScriptableObject's inspector doesn't update properly 0 Answers

Dynamic casting? 1 Answer

Project settings unavailable 0 Answers

Draw rect color disappearing when any input is detected 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