A Better Wave Spawner (Point-Based-System) - Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ม.ค. 2025

ความคิดเห็น • 101

  • @kremmidis_773
    @kremmidis_773 10 หลายเดือนก่อน +6

    For anyone wondering why your next wave isn't starting, the code in the video ins't complete, but there is the completed code in the description.

  • @SkylorBeck
    @SkylorBeck ปีที่แล้ว +1

    Very helpful. Not too complex so as to lose sight of the goal but complex enough to make it interesting. Thank you!

    • @ThatOneUnityDev
      @ThatOneUnityDev  ปีที่แล้ว +1

      Thanks for watching! Glad you enjoyed the video! :)

  • @wrayo
    @wrayo 2 ปีที่แล้ว +7

    Such a great video! Love how the code is so simple and makes it open to adding in other elements as well!

  • @ImOmerAhmed
    @ImOmerAhmed 2 หลายเดือนก่อน +1

    I'm using Godot, but this tutorials was still able to help me understand the basic logic and functionality of the code
    Thanks for the help! The waves are working perfectly and the prototype of my game is actually really really fun!! :)

    • @ThatOneUnityDev
      @ThatOneUnityDev  2 หลายเดือนก่อน +1

      @@ImOmerAhmed That's great! Thanks for sharing! It's always nice to hear about other people's game projects! :D

  • @mauriciopartnoy2789
    @mauriciopartnoy2789 2 ปีที่แล้ว +7

    I did something similar for a wave based space shooter a couple of years ago. Instead of individual units the spawner "bought" small groups of enemies called "PricedWaves". Developers think alike it seems :P

  • @fatpenguin_
    @fatpenguin_ 2 ปีที่แล้ว +1

    Thanks for this tutorial, I've been looking for a tutorial that's short, and understandable! I'm making a top down shooter that's based on wave system where this video helped me a lot!

  • @unscriptedlogicgames
    @unscriptedlogicgames 2 ปีที่แล้ว +2

    Hey! This is a pretty cool concept. Never have I thought about it this way.

  • @Bokaley
    @Bokaley ปีที่แล้ว +2

    Very cool guide! So much space to add my own features 👍

  • @tienvantheten8924
    @tienvantheten8924 5 หลายเดือนก่อน +1

    What a great video man, thank you!

    • @ThatOneUnityDev
      @ThatOneUnityDev  5 หลายเดือนก่อน

      Thank's for watching! Glad you liked it! :)

  • @CescosGames
    @CescosGames ปีที่แล้ว +1

    Very cool approach - thank you for the guide!

  • @lucashanscom2697
    @lucashanscom2697 2 ปีที่แล้ว

    Thanks man! Works and is a happy addition to any spawn system.

  • @steventomek4236
    @steventomek4236 ปีที่แล้ว +2

    amazing video, but I've got a problem , while running your code (at 3:30 in video) my Unity freezes for more than an hour and crashes, idk why it might be a problem but I think I need to rewrite the code

    • @ThatOneUnityDev
      @ThatOneUnityDev  ปีที่แล้ว

      Did you use the 2 scripts in the description? You need to make sure you set EVERYTHING correctly in the inspector, give your wave spawner the "WaveSpawner" tag, and attach the enemy wave tracker to your enemies.

    • @steventomek4236
      @steventomek4236 ปีที่แล้ว

      ​@@ThatOneUnityDev​ so I've spend some time with this code and everything is working fine, but i sometimes get errors like :
      ObjectDisposedException: SerializedProperty enemiesToSpawn.Array.data[0] has disappeared!
      or
      InvalidOperationException: The operation is not possible when moved past all properties (Next returned false)
      and
      type is not a supported pptr value
      UnityEditor.RetainedMode:UpdateSchedulers ()
      I don't really know what is up with that one, it won't crash my game but it makes confusing mistakes for example the last enemy in the enemiesToSpawn Array will spawn and won't erase that last Array slot and new array is being created in the same time so unity is getting upset about this. So it's not really a big thing but it's an error message so I don't think that I can ignore this one.
      I don't really know how to resolve this one, i thought about creating coroutine to delete array index after 1 second but It did not work as I thought it would. If you could tell me what could cause this to happen i would be glad.

    • @Matthew-iy5lt
      @Matthew-iy5lt ปีที่แล้ว

      @@steventomek4236 Did you ever find a solution for this? I'm currently having the same issue.

    • @steventomek4236
      @steventomek4236 ปีที่แล้ว

      @@Matthew-iy5lt for the ObjectDisposedException etc... ? no not really, I've run some tests and research, and come to conclusion that this error message literally does nothing XD,
      It doesn't cause any lag (I left the game ride on for 10h nothing lagged so that's it) it doesn't crash anything at any time and I think it's just unity's way of telling us
      "omg something deleted this serialized field and I don't know what plz help"
      I might be wrong but I don't have any idea for fixing this issue XD
      On the other hand I plan on cleaning my code up , setting up setters getters and references instead of public variables etc so maybe then I will invent solution, but for now I can't help myself or you , sorry :C
      If you find a solution please let me know ^^

    • @Matthew-iy5lt
      @Matthew-iy5lt ปีที่แล้ว

      @@steventomek4236 Apparently it's an issue with unity. The only time this issue appears for me is when I have "WaveSpawner" selected in the hierarchy not sure if it's the same for you. The error message doesnt appear as long as I dont have it selected.

  • @perdoist3627
    @perdoist3627 11 หลายเดือนก่อน +1

    Nice tutorial. But I just wanna ask that how can I add a waiting time between waves. I tried routines but didn't work.

    • @ThatOneUnityDev
      @ThatOneUnityDev  11 หลายเดือนก่อน +1

      At the bottom of fixed update, you will notice an if statement, this is checking if the wave time is less than or equal to 0, and all enemies are defeated.
      Inside is when it updates to a new wave. Rather than having it start a new one right away, you can implement a timer, or even have an additional bool, that you trigger whenever you like in your game.
      Happy creature slaying! :)

    • @perdoist3627
      @perdoist3627 11 หลายเดือนก่อน

      @@ThatOneUnityDev thanks dude.

  • @alientizim
    @alientizim 2 ปีที่แล้ว

    Thank you!!! Explained really well! It works!!!

  • @bubchudlar5629
    @bubchudlar5629 11 หลายเดือนก่อน +1

    Hey, this is great stuff and exactly what I needed for a combat-based infinite runner I'm making. However I'm using object pools for my enemies since it's for mobile, and I'm trying to work out what I'd change in this code to make it use pools instead of instantiate calls. I'd guess I need something in the Enemy class that retrieves the pooler from the enemies?

    • @ThatOneUnityDev
      @ThatOneUnityDev  11 หลายเดือนก่อน

      Thanks for watching! Exactly, anywhere we are instantiating, replace it with your pool logic, and the same goes for destroying! Otherwise everything is the exact same! Cheers! :)

  • @RictorScale
    @RictorScale ปีที่แล้ว +1

    This was perfect, thanks so much!

  • @DweebProductions
    @DweebProductions 3 หลายเดือนก่อน +1

    Hey ThatOneUnityDev, I was wondering how to make a difficulty system overtime because for my game it wouldn't work with all enemies spawning at once.

    • @ThatOneUnityDev
      @ThatOneUnityDev  3 หลายเดือนก่อน

      I'm not too sure I understand. So in the code for the wave spawner, there is a variable to control the wave duration, which slowly release enemies based on that number. Then when they are all defeated, the wave number increases and the difficulty increases as well.

    • @DweebProductions
      @DweebProductions 3 หลายเดือนก่อน

      @@ThatOneUnityDev Okay thanks a lot! I'm making kind of like a plants vs zombies kind of game so I wanted spawning enemies to be slow and progressive, thanks for the help!

  • @diggin8741
    @diggin8741 2 ปีที่แล้ว +1

    That was really nice!! Ty bro

  • @daviapenas
    @daviapenas ปีที่แล้ว +1

    This is gold

  • @Bardent
    @Bardent ปีที่แล้ว +1

    This is great!!

  • @BigMemerMan2
    @BigMemerMan2 18 วันที่ผ่านมา

    cannot divide by zero error?

  • @ChristiaanSC
    @ChristiaanSC 2 ปีที่แล้ว

    Thank you for the great tutorial.

  • @blazingice3490
    @blazingice3490 2 ปีที่แล้ว

    for smr on my system the wave spawner doesnt function at all.. it just says entering play mode.. but never loads up neither on engine oor in build

  • @naoeoneat8266
    @naoeoneat8266 2 ปีที่แล้ว +2

    i really like this system, one problem though, when i kill an enemy, in the enemy script i use the Destroy method, and inside the Spawned Enemies list the game object is empty, but the space in the list is still there, i dont know how to fix this issue

    • @paulblart7378
      @paulblart7378 6 หลายเดือนก่อน +1

      Late, but be sure to remove the enemy from the list before destroying it.

  • @MIKE-MURPHY
    @MIKE-MURPHY 2 ปีที่แล้ว +1

    My currwave doesn't update to a new one after I kill the enemies. One wave and it's over. Am I missing something?

    • @ThatOneUnityDev
      @ThatOneUnityDev  2 ปีที่แล้ว +3

      No, your not missing anything. I left it that way on purpose, as you might have a different 'event' that increases the wave. Ex: killing all enemies, exiting a shop, etc. Whenever you want the next wave to start, all you need to do is increase the currwave variable by 1, and call the generate wave function. If you have any issues, you can head over to the discord, and we will be glad to help! :)

  • @drorgu102
    @drorgu102 9 หลายเดือนก่อน

    Hey any chance you can help me out
    I am getting Error \ Exception :
    "ObjectDisposedException: SerializedProperty enemiesToSpawn.Array.data[1] has disappeared!"
    I really cant understand what I need to do here
    is it a way to ignore that exception ? . It's really not so important if some enemies are disappearing.

    • @drorgu102
      @drorgu102 9 หลายเดือนก่อน

      I may found a solution with this:
      void OnValidate() {
      enemiesToSpawn.RemoveAll(item => item == null);
      }

  • @mr_sunny9074
    @mr_sunny9074 ปีที่แล้ว

    Is this good for a 2 side scroller wave defense?

  • @LumpyCustard521
    @LumpyCustard521 2 ปีที่แล้ว +6

    Hi! First of all this is great! but is there a way for enemys to spawn in multiple locations?

    • @ThatOneUnityDev
      @ThatOneUnityDev  2 ปีที่แล้ว +2

      Thank you so much! You can for sure expand upon this to allow for multiple locations! If you need help, you can pop over to the discord and either myself or others will give you a hand! :)

    • @pockets08
      @pockets08 2 ปีที่แล้ว +2

      JUst create a list similar to the enemies. When calling for the spawn point, create a random range to select from the list to choose its destination. Hope that helps!

    • @baldchessman
      @baldchessman ปีที่แล้ว

      Create an array of spawn points and then on spawn you loop through them and pick a random one

  • @drorgu102
    @drorgu102 9 หลายเดือนก่อน

    wow really cool!!
    Question: Can you help understand how can I make the "SpawnLocation" object
    to make the enemies spawn with random positions around the player?

    • @ThatOneUnityDev
      @ThatOneUnityDev  9 หลายเดือนก่อน

      If i'm understanding correctly, all you would need to do is before spawning the enemy, just grab a random point inside a circle around the player, and set the spawn position to be that point.

  • @Benkaera
    @Benkaera ปีที่แล้ว

    If i change cost even on 1 digit from 1 to 5, unity stops working

  • @PH0S
    @PH0S 2 ปีที่แล้ว +1

    Why is the one in the desc different than the one in the video?

    • @ThatOneUnityDev
      @ThatOneUnityDev  2 ปีที่แล้ว +1

      A bunch of people flooded my discord asking for extra functionality. The link in the description is an improved version.

  • @Moomit
    @Moomit 2 ปีที่แล้ว +1

    When i execute this Unity freezes OnEnterPlaymode loading and keeps loading.

    • @bluefiregaming1755
      @bluefiregaming1755 2 ปีที่แล้ว

      Same did you fix it?

    • @Moomit
      @Moomit 2 ปีที่แล้ว

      @@bluefiregaming1755 Unfortunately no.Someone pointed i should remove the .Clear line but not tried that option

    • @bluefiregaming1755
      @bluefiregaming1755 2 ปีที่แล้ว

      Thanks I’ll try that

  • @smaguy64
    @smaguy64 2 ปีที่แล้ว +1

    Your tutorial is really awesome, honestly one of the best i've seen for wave spawner.
    But how do you tackle the problem of spawning on multiple location?

    • @ThatOneUnityDev
      @ThatOneUnityDev  2 ปีที่แล้ว +2

      Thank you so much! :) .. In the code in the description, I have added support for multiple locations! :)

    • @smaguy64
      @smaguy64 2 ปีที่แล้ว +1

      @@ThatOneUnityDev thank you so much!

  • @lawrencemiller2642
    @lawrencemiller2642 ปีที่แล้ว

    when i get to wave 3 thescript spawns all of the enemis in 1 sec fix pls

    • @ThatOneUnityDev
      @ThatOneUnityDev  ปีที่แล้ว +1

      The reason this is happening, is because you have a large amount of enemies spawning on that wave, so many in-fact, that it cant stretch them over your wave duration. To fix this, you either need to increase your wave duration, or have other higher value enemies it can choose from, to lower the amount that are spawning. Alternatively, you can replace the GenerateWave function to this: pastebin.com/fCGkaBFS ... This will default a 0.25f second delay when you run into this problem.

    • @lawrencemiller2642
      @lawrencemiller2642 ปีที่แล้ว +1

      @@ThatOneUnityDev ohh ty man

  • @MonsterKazzie
    @MonsterKazzie 2 ปีที่แล้ว

    How do I change the waves? And how do I get to a certain wave, the level ends

    • @ThatOneUnityDev
      @ThatOneUnityDev  2 ปีที่แล้ว

      The code in the description starts the wave when all the enemies are killed.

    • @MonsterKazzie
      @MonsterKazzie 2 ปีที่แล้ว

      @@ThatOneUnityDev Thank you!

  • @Easyriderr
    @Easyriderr 2 ปีที่แล้ว

    When do you think a Booling system will be necessary,

    • @ThatOneUnityDev
      @ThatOneUnityDev  2 ปีที่แล้ว

      If you mean object pooling, you can feel free to add that at any point. But as a general rule I usually tend to add object pooling if I spawn an object 20 or so times in a project.

  • @Loopa300
    @Loopa300 2 ปีที่แล้ว

    Is there a way that the enemies go away after a few seconds

  • @caster2819
    @caster2819 2 ปีที่แล้ว

    man this is gud stuff

  • @JohnnyBriones
    @JohnnyBriones 2 ปีที่แล้ว +3

    Hi, I can't get enemies to spawn after I killed them all. For the enemy tracker, I have tags on my enemies of "Weak Point" so I switched that out for the "WaveSpawner" but it is not working right. Any help on this would be greatly appreciated!
    void OnDestroy()
    {
    if (GameObject.FindGameObjectWithTag("Weak Point") != null)
    {
    GameObject.FindGameObjectWithTag("Weak Point").GetComponent().spawnedEnemies.Remove(gameObject);
    }
    }

  • @nightsmusicuk
    @nightsmusicuk ปีที่แล้ว

    hey there, i've managed to get this to work fine, apart from the spawn location seems static? if the object in the field changes its x & y, the wavespawner doesnt seem to notice this and keeps spawning the enemies at the original x & y point, how do i work around this? thx

    • @ThatOneUnityDev
      @ThatOneUnityDev  ปีที่แล้ว

      That's odd. I tested it, and it appears to be working as you intended. Perhaps you are moving the wrong object? If you are using multiple spawn locations it is set to ping pong between all of them.

  • @Rjf32
    @Rjf32 9 หลายเดือนก่อน +1

    Sry for da aggression video definitely isnt terrible just been had a couple terrible hours trying to figure shit out but got it my bad if anyone runs into a problem feel free to ask i definitely ran into a couple 😅

    • @ThatOneUnityDev
      @ThatOneUnityDev  9 หลายเดือนก่อน

      Thanks for watching! I'm glad you enjoyed it. 😂

  • @JOHNSMITH-sj3lg
    @JOHNSMITH-sj3lg 2 ปีที่แล้ว

    Great System thank you very much the only problem i have is that on wave 4 or 5 the spawn interval is 0 and every enemy spawn at the same time this looks realy buggy can u help me fix this?

    • @pfredot4673
      @pfredot4673 2 ปีที่แล้ว

      Did you find the solution? I'm having the same problem.

    • @JOHNSMITH-sj3lg
      @JOHNSMITH-sj3lg 2 ปีที่แล้ว

      @@pfredot4673 i found a workaround i made a if statement
      if(spawnInterval

    • @pfredot4673
      @pfredot4673 2 ปีที่แล้ว +1

      @@JOHNSMITH-sj3lg Thank you for the reply, i actually made something similar too.

    • @PedroHenrique-nk5rf
      @PedroHenrique-nk5rf 2 ปีที่แล้ว +2

      @PF Redot just change waveDuration to float.
      It will look like this: public float waveDuration;
      The issue is with the integer division, when the number of enemies is very high, the resulting value is 0.

    • @JOHNSMITH-sj3lg
      @JOHNSMITH-sj3lg 2 ปีที่แล้ว

      @@PedroHenrique-nk5rf thank you sooo much brother👌

  • @iR3dyOfficial
    @iR3dyOfficial 2 ปีที่แล้ว

    I'm subbing

  • @Seshua87
    @Seshua87 ปีที่แล้ว

    After the video I spent awhile skimming through the video because I was like where did I miss the part where it continues to spawn waves?? I didn't realize that you left that part out and that the code is in the pastebin links. Just a heads up but maybe make a pinned comment letting people know that :)

    • @ThatOneUnityDev
      @ThatOneUnityDev  ปีที่แล้ว

      That's a good idea! Originally I wasn't going to add that feature, as you may want to spawn the wave according to some other parameter (after upgrading for example). But I added it after the fact, as well as additional spawn points, and a few other features people in the discord were asking about.

  • @JoeyLoos0412
    @JoeyLoos0412 2 ปีที่แล้ว

    What logic is in your enemy scripts?

    • @paulblart7378
      @paulblart7378 2 ปีที่แล้ว +1

      Why does that matter? This is a tutorial on spawning enemies, not making them

  • @biki_02
    @biki_02 2 ปีที่แล้ว

    great video❤.Please, upgrade your microphone.

  • @dys3276
    @dys3276 2 ปีที่แล้ว

    Error
    CS0101
    :(

    • @ThatOneUnityDev
      @ThatOneUnityDev  2 ปีที่แล้ว

      You either have 2 WaveSpawner scripts in your project file, or your script isn't named the same as the class 'WaveSpawner'. - Minus the quotes.

    • @dys3276
      @dys3276 2 ปีที่แล้ว

      @@ThatOneUnityDev Thank youuu

  • @ВалентинКритенко
    @ВалентинКритенко 2 ปีที่แล้ว

    Ths for video) I am lose 1 hours, list empty enemies, bug Curr wave = 0, fuck, in unity inspector in fields.

  • @桔梗qaq
    @桔梗qaq 6 หลายเดือนก่อน

    i love you,good guy!

    • @ThatOneUnityDev
      @ThatOneUnityDev  6 หลายเดือนก่อน

      Haha, tysm! I'm flattered! ;)