Help: Video 97 of 2D course: WaveConfig Vs. waveConfig

Hi everyone,

I’m currently working on the 2D course & am working through the Laser Defender section. I was hoping somebody could explain a certain section in a bit more detail as I’m having trouble understanding it completely.

In our EnemySpawner.cs Script our coroutine begins with the following:

" private IEnumerator SpawnAllEnemiesInWave(WaveConfig waveConfig) "

I understand that using “WaveConfig” allows us to access the WaveConfig.cs script, but I still have not grasped why we use “waveConfig”, what it does & also where it comes from.

I’ve looked over the WaveConfig.cs script & I can’t see a “waveConfig” reference in it at all, so I’m confused as to how we’re using it in the EnemySpawner.cs script. I tried looking it up but was unsure what to look for in the Unity Docs, unfortunately.

I don’t really want to go any further in the course until I’ve got a better understanding of this, so if anyone can help me out I’d be very appreciative :slight_smile:
Thank you!

Hi Sombra,

The coroutine starts with StartCoroutine. SpawnAllEnemiesInWave is a method with IEnumerator as the return type. Furthermore, it takes in a WaveConfig object as an argument, not a script.

Inside the parentheses, we declared a local variable for our SpawnAllEnemiesInWave method. You can rename waveConfig if you want. blah would work as well.

Inside the method block, the received object can be accessed via the variable name. This technique is called method overloading.

Since this is our method, you won’t find any answer in the Unity docs.


See also:

1 Like

Hi Nina,

Thank you for your reply!

Ok so based on what you’ve said, I think my biggest misunderstanding was that WaveConfig.cs is a ScriptableObject, & I had approached it under the assumption that it worked much in the same way as MonoBehaviour.

So to make sure I understand it: We simply created “waveConfig” as a way to reference the ScriptableObject we would like to access within our SpawnAllEnemiesInWave method?

The way you’ve explained it has definitely helped me understand it a bit better (I think lol). However, I think I need to learn a bit more about ScriptableObjects & the IEnumerator return type :slight_smile:

I feel more comfortable moving on to the next section of the course, so thank you. Hopefully, all these concepts will become clearer the more I progress through the course.

Thank you for your help :slight_smile:

Much simpler. Objects inheriting from the ScriptableObject or the MonoBehaviour class are objects. The method does not care from which class your object inherits as long as the object is of the expected type.

C# does not have anything to do with Unity, so regard your scripts and Unity stuff as two different things. ScriptableObject objects can be created in Unity. They appear in your Assets folder. I don’t know what exactly is going on in Unity because Unity is not open-source.

For this reason, I simply imagine that if I assign something from the Assets folder to an exposed variable in a component in the Inspector, Unity will create a normal C# object. I presume that Unity does its stuff, so I can focus on C# only.

If you want to dive deeper into C#, you could take a break from this course and watch this free course by Bob Tabor.

1 Like