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 feneq · Mar 04, 2013 at 09:29 PM · arrayperformanceupdateoptimizeiterate

Is iterating through an array in Update() a bad idea?

I'm trying to optimize my game a bit but I think I need to get a better grasp about what is going on in my program before I can do that with this specific problem.

Right now in Start() I'm instantiating 50 enemies off screen and deactivating them. I then have another function in Update() that will activate them when necessary. My problem lies in the for loop in Update().

Is it a bad idea to iterate through an array in the Update() function? My instinct tells me yes but again I'm trying to get a better grasp about what is going on. Does the game hang while it iterates through the array to try and find the condition it's looking for? Should I be trying to come up with a better solution or am I making a fuss over nothing? I'm concerned that the framerate could take a hit or players will see stutters as my game iterates through an array during run time. I haven't noticed a performance hit myself but I only have my PC and a Galaxy S3 to test my game on, it's not really fair to assume all my players (if I have any) will be playing on a Galaxy S3.

Comment
Add comment · Show 1
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 Fattie · Mar 05, 2013 at 05:30 AM 0
Share

robert explains how to test the performance.

but what you are doing sounds totally incorrect. there is no reason I can think of that you would possibly need to check EVERY FRA$$anonymous$$E that something should be active? it simply makes no sense at all.

just think of a video game. when SO$$anonymous$$ETHING HAPPENS you then make something active or not. for example, a character is blown up, so it becomes inactive. you add bullet or a new enemy .. something becomes active

it could be you totally misunderstand how active/not active is used. perhaps you should explain what you are doing in another question and someone will point out how to do it without such an approach.

1 Reply

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

Answer by robertbu · Mar 04, 2013 at 10:04 PM

Depends on the size of the array and what processing you are doing on each element. Modern computer/smart phones/tables can do an amazing amount of processing in 1/30 of a second or so. And yes, if you have a slow iteration in an array, your game can slow way down or appear to hang.

To get an idea if you have an issue with lesser hardware, put your array lookup in a loop, so you execute the lookup multiple times per frame. Then start testing to see what number cause a slowdown on your Galaxy S3...2 times, 10 time, 100 times,1000 times. If the number is low, you have a potential issue. If it is higher you are probably okay, though nothing is sure until you test it on the actual hardware.

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 feneq · Mar 04, 2013 at 10:29 PM 0
Share

That makes sense. Thanks, I will run some test.

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make an array of all visible objects 1 Answer

Is Using Coroutines Actually Faster Than Update? 1 Answer

Creating Auditorium Seating That Doesn't Kill My Machine 0 Answers

Intensive Shaders + Dynamic Batching 1 Answer

Performance Optimization ~Function Update: Loop or Once ? 5 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