Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by kadenatmore · Aug 21, 2016 at 01:29 AM · crashlagspawning

How to make enemies stop spawning

So I have an infinite zombie spawning game, much like Call of Duty: Zombies, and I have 8 GameObjects around the map that act as spawners spawning 1 enemy every 11 seconds, or eight enemies every 11 seconds if you count all the spawners, but the problem is, within a minute or so, there are so many enemies that the game lags then crashes, so how can I make enemies stop spawning after so many are spawned then start spawning again when that number is reduced by the player killing them, and how many enemies do you recommend exist at once? Thanks in advance!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Effervescence · Aug 21, 2016 at 05:51 AM

@kadenatmore Are you using object pooling for these enemies? If you are, then it's easy enough to limit the enemies by limiting how many you create in the first place. Object pooling is basically creating a list of the gameobjects you want to pool, and setting them active/inactive as needed. Link to tutorial in case you haven't seen it yet: https://unity3d.com/learn/tutorials/topics/scripting/object-pooling .

If you're not using object pooling (although I would recommend doing so), you could technically keep a counter of how many enemies are on-screen, stop spawning when they reach a certain point, and restart after they fall below another point, but...that's probably not a good way to go about it ^^'

Finally, as for how many enemies should exist at once...honestly it depends on how much they're doing (do they actually go after the player and shoot bullets at them or do they just stand there and kill the player on contact?). Best way to find out is just to test different numbers, I'd say. ^^'

Comment
Add comment · Show 3 · Share
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
avatar image kadenatmore · Aug 21, 2016 at 08:07 PM 0
Share

Yeah I'm not using pooling, I don't think, I didn't write the spawn code myself, but I'm 99 percent sure it uses Instantiate, and they just run into the player and do 10 damage every second they are in contact, is object pooling god for spawning enemies infinitely (But only so many at once)?

avatar image Effervescence kadenatmore · Aug 21, 2016 at 08:16 PM 0
Share

Yeah, object pooling is definitely very good for things like enemy spawning, bullets, etc. Instantiate() and Destroy() are a bit more taxing on your computer.

avatar image kadenatmore Effervescence · Aug 21, 2016 at 09:31 PM 0
Share

Sorry for this, but I'm horrible at scripting, could you provide with a script or link ti script please if possible, thanks!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Script Crashing Unity 1 Answer

What should I do to prevent crashing? 0 Answers

How can I spawn without glitch 1 Answer

Script causing lag 1 Answer

Why does unity crash leads to direct3D and hardware acceleration disappear ? 2 Answers


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