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.
 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!
 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.  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!
 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();
         
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
Adding space() to BeginHorizontal() causes extra vertical spacing after certain amount. 1 Answer
Create a greyed out value field in the editor? 2 Answers
Making a custom editor window much like the Animator window? 0 Answers
How to create a selection menu in the inspector for classes and their methods? 1 Answer
Editor Int sliders affecting each other 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                