Search Unity

Unity Editor Inspector gets broken when using list with classes.

Discussion in 'Editor & General Support' started by forni_faunea, Jun 20, 2022.

  1. forni_faunea

    forni_faunea

    Joined:
    Dec 6, 2017
    Posts:
    1
    Hey folks!

    I have a script that uses a Class inside a list and serialized system. But, for some reason, it is messing up all my Inspector when I try to use it. Anyone had this issue before? Any idea how to solve it? Screenshot_2.png


    Screenshot_3.png
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [System.Serializable]
    6. public class WaveSetup
    7. {
    8.     public string name;
    9.     public float delay;
    10.     public GameObject enemy;
    11.     public int spawnAmount;
    12.     public int waveTime;
    13. }
    14.  
    15. [System.Serializable]
    16. public class Wave
    17. {
    18.     public string name;
    19.     public List<WaveSetup> setup;
    20. }
    21. public class WaveController : MonoBehaviour
    22. {
    23.     public float TimeWaves = 1f;
    24.     public List<Wave> waves;
    25.     private int waveNumber = 0;
    26.     private int enemyCount = 0;
    27.     private Wave currentWave;
    28.     private WaveSetup currentSetup;
    29.  
    30.     void Start()
    31.     {
    32.  
    33.         currentWave = waves[waveNumber];
    34.         currentSetup = currentWave.setup[0];
    35.         print(currentWave.name);
    36.         StartCoroutine("SpawnLoop");
    37.  
    38.  
    39.     }
    40.     private void Update()
    41.     {
    42.         print("Wave: " + waveNumber + "/" + waves.Count);
    43.  
    44.         if (waveNumber >= waves.Count)
    45.         {
    46.             print("End of Waves");
    47.             StopSpawnLoop();
    48.             Destroy(gameObject);
    49.         }
    50.     }
    51.  
    52.     IEnumerator SpawnLoop()
    53.     {
    54.         while (true)
    55.         {
    56.  
    57.             if (currentSetup.spawnAmount != 0 && enemyCount < currentSetup.spawnAmount)
    58.             {
    59.                 Instantiate(currentSetup.enemy, gameObject.transform.position, currentSetup.enemy.transform.rotation);
    60.                 enemyCount++;
    61.                 print(enemyCount + "/" + currentSetup.spawnAmount);
    62.                 yield return new WaitForSeconds(currentSetup.delay);
    63.             }
    64.  
    65.             if (enemyCount == currentSetup.spawnAmount && waveNumber < waves.Count)
    66.             {
    67.                 yield return new WaitForSeconds(currentSetup.waveTime);
    68.                 nextWave();
    69.             }
    70.  
    71.             yield return null;
    72.         }
    73.     }
    74.  
    75.     public void nextWave()
    76.     {
    77.         print("Callou!");
    78.         waveNumber++;
    79.         currentWave = waves[waveNumber];
    80.         currentSetup = currentWave.setup[0];
    81.         enemyCount = 0;
    82.         print(currentWave.name);
    83.     }
    84.  
    85.     public void StopSpawnLoop()
    86.     {
    87.         StopCoroutine(SpawnLoop());
    88.     }
    89.  
    90. }
     

    Attached Files:

  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    Known issue. It usually helps to deselect and select the object again.