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 /
  • Help Room /
avatar image
0
Question by Ventext · Sep 18, 2016 at 01:29 PM · instantiationloops

Instantiating in a for loop is causing an infinite loop?

ok, so I have been trying to figure this out for two days now. The for loop in my StartingFloor() function works fine if I comment out the instantiate like, but otherwise, it crashes.

var Tile : GameObject; var gameStart = true; function StartingFloor(FloorTile : GameObject) { var tilesInRow = 7; var rowsInColumn = 7; var HALF_ROW = 3; var TILE_SIZE = 0.24; var tileY = 0; for(var tileX = 0; tileX < tilesInRow; tileX++) { var tilePosition = Vector3(-1 (HALF_ROW TILE_SIZE) + (tileX * TILE_SIZE), tileY, 0); Instantiate(FloorTile, tilePosition, FloorTile.transform.rotation); if((tileX - (tilesInRow - 1)) % tilesInRow == 0) { tileY += 1; } yield WaitForSeconds(3); Debug.Log(tileX); } } function Start () { StartingFloor(Tile); }

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 soccer1mt · Sep 18, 2016 at 05:58 PM 0
Share

Posting code using correct tools provided will make it more readable and more likely to get answered.

2 Replies

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

Answer by Ventext · Sep 28, 2016 at 12:59 AM

I AM SUCH AN IDIOT!!!! I attached the script for instantiating the tiles to the tiles. So every time one spawned, it spawned another just like it, and so on and so forth, causing infinite objects to spawn. I easily fixed the problem by creating an empty object named "TileSpawner" and attached the script to that, getting rid of the infinite instantiating problem. Gosh I can be so dumb sometimes.

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 lawrence-parry · Sep 19, 2016 at 01:54 AM

For a start when posting a question use the 101 button to add code like this:

  var Tile : GameObject;
  var gameStart = true;
 
  function StartingFloor(FloorTile : GameObject)
  {
     var tilesInRow = 7;
     var rowsInColumn = 7;
     var HALF_ROW = 3;
     var TILE_SIZE = 0.24;
     var tileY = 0;
 
     for(var tileX = 0; tileX < tilesInRow; tileX++)
        { 
           var tilePosition = Vector3(-1 (HALF_ROW TILE_SIZE) + (tileX * TILE_SIZE), tileY, 0);
           Instantiate(FloorTile, tilePosition, FloorTile.transform.rotation);
           if((tileX - (tilesInRow - 1)) % tilesInRow == 0) { 
              tileY += 1;
           }
        yield WaitForSeconds(3); 
        Debug.Log(tileX);
     }
  }
  function Start ()
  {
     StartingFloor(Tile);
  }

As for what the problem is I'm not too sure, make sure the tile position and rotation you are setting is valid, try testing it with the position and rotation set to 000 or something. So for testing purposes try replacing your instantiate with:

 Instantiate(FloorTile, Vector3.zero, Quaternion.identity);

If that fixes the crash then that lets you know the problem is the position and/or rotation you are setting. Hope this helps :)

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 Ventext · Sep 20, 2016 at 01:26 AM 0
Share

I tried that. I even tried simply instantiating the tile with no other perimeters whatsoever, just Instantiate(FloorTile) but it still causes an infinite loop. Thanks for the help though. (and telling me about the 101 button. can you tell i'm new to all of this?)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to break reference from .asset classes and runtime copied values? 2 Answers

How to get objects to spawn in according to rules 1 Answer

Trying to name a gameObject - loop suddenly exiting. 1 Answer

Store instantiated object in List 2 Answers

Instantiating prefab causes existing instances to change values 1 Answer


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