Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Asle · Mar 26, 2010 at 12:28 PM · freezewhile-loop

What is wrong in my code - Unity freezes

Hi I made a code that I will eventually use for stacking objects, but are at the moment just testing if it executes correctly which it doesn't and I can't seem to figure out what is wrong.

The Code:

var countx:int=0; var county:int=0; var countz:int=0;

function Update () {

 while (county < 101){
     ++countx;
     Debug.Log("1: "+countx+","+county+","+countz);
     if (countx==200) {
         ++countz;
         Debug.Log("2: "+countx+","+county+","+countz);
         if (countz==200) {
             ++county;
             countz=1;
             Debug.Log("3: "+countx+","+county+","+countz);
         }
         if (county< 100)countx=1;           
     }
     Debug.Log("4: "+countx+","+county+","+countz);
 }   

}

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
3
Best Answer

Answer by duck · Mar 26, 2010 at 12:43 PM

Are you trying to achieve something like this?:

for (var countY=0; countY < 100; ++countY) {
    for (var countZ=0; countZ < 200; ++countZ) {
        for (var countX=0; countX < 200; ++countX) {
            // Debug.Log(countX + ", " + countY + ", " + countZ);
        }
    }
}

(i.e. iterate through every point in a 200x200x100 structure?)

Using nested 'for' loops like this is the typical method for iterating through a 2d or 3d set, however the figures you have give a rather large number of total iterations. For this reason, I have the Debug.Log line commented out in my example, because if you run it, that code will generate 4 million debug.log lines (which may cause your computer to seem as though it has locked up while printing them all to the console).

Note, if you're planning to stack gameobjects using something like this, you'll end up with 200 x 200 x 100 objects - that's 4 million gameobjects - something that is not really feasible to work with in Unity.

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 Asle · Mar 28, 2010 at 06:01 AM 0
Share

I am making a kind of a stesstest for unity to test how many objects I can have in a scene at the same time, I am not generating all 4 million objects at the same time, but I wanted to have an array of positions where I could put the objects as I generate them.

I generate objects by pressing the mousebutton.

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

No one has followed this question yet.

Related Questions

Unity Crashes From While Loop and Can't fix 0 Answers

Do-while loop freezes the engine when running the game -1 Answers

How to use a WHILE LOOP? Obviously not inside ***function Update*** 3 Answers

Unity Crashes From While Command 7 Answers

While loop causes game to freeze 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