Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Glen · Aug 17, 2010 at 04:07 PM · instantiateiphone

Spawning hundred enemies on iPhone

In one level I have 120 enemies moving from the right side of the screen to the left in rows. The goal is to kill all before they reach the left side. My game is 2d and makes use of Brady's SpriteManager 2. I have up to 15 enemies on the screen at a time. I have tried following solutions for making this run smoothly:

  1. Instantiating 10-15 enemies every time "one row" is cleared. This is not a good solution as the game freezes shortly as the enemies are being instantiated.

  2. Instantiating all enemies at the beginning of the level, and deactivating them all until they are needed. Same problem as in solution 1. When 15 enemies is activated, the game freezes.

  3. Instantiating all enemies at the beginning of the level, and disable the renderer on every game object until they are needed. This works okay, but it seems like it is not running completely smoothly.

Do you have a better solution or is this the way to go?

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

4 Replies

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

Answer by Morothar · Aug 17, 2010 at 04:52 PM

I'd go with option 3 with a small change. I'd hold them offscreen until needed instead of enabling/disabling the renderer. Also, keep in mind that you have 120 objects with the same number of scripts running. Check your Update() in the enemies script and try to optimize it. If you have unity pro you could run a copy of your project in pro and check the profiler for anything unusual.

Comment
Add comment · Show 1 · 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 Glen · Aug 21, 2010 at 07:59 AM 0
Share

Thank you everyone for your suggestions. I just found a thread about layer masking. In my game I have a projectile that raycasts in every update. When having so many enemies, will it make sense to set a different "layer" to the enemies off screen, as there are no need for them to be tested for collision? Thanks again.

avatar image
1

Answer by Whimsical · Aug 17, 2010 at 04:22 PM

You can also try to replace the sprite manager with something more light-weight of your own. I have nothing against Brady's SpriteManager, it's in fact a nice tool, but it is a bit overkill for some uses, especially on iOS devices.

Comment
Add comment · Show 2 · 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 spinaljack · Aug 18, 2010 at 01:09 AM 0
Share

Isn't the sprite manager designed for use on the iPhone?

avatar image Whimsical · Aug 19, 2010 at 01:16 AM 0
Share

Probably, but "Built-to-fit-all-needs"-tools are usually a bit more consu$$anonymous$$g by nature. The best way to go on performance-restricted platforms like iOS is to build something of your own that really only does what you need it to do. That's usually the better way to go.

avatar image
0

Answer by Wolfram · Aug 17, 2010 at 04:23 PM

Try optimizing the causes, not the symptoms: How complex is a single enemy? Especially draw calls, maybe also number of sub-objects, scripts, components, etc. Reduce it to the bare minimum.

Comment
Add comment · 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
0

Answer by JordanCannaday · Jul 22, 2011 at 01:50 PM

Iphone has many enemies including all of the androids and droids blackberrys and sprints palm pre and more

Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

Can't seem to destroy instantiated objects. 1 Answer

Fruit Ninja - Cut fruit effect 3 Answers

Finding children of an instantiated object 1 Answer

Accessing prefab instances at runtime (unity iphone) 2 Answers

Have a spawning issue on iOS 0 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