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 Zack-Londres · Feb 25, 2013 at 09:32 PM · crashcrashingstartup

Crash on play befor the game even starts.

Im making a randomly generated game that has a number of pieces and then place there own pieces, that place there own pieces.... and so on till it reaches a limited number of pieces. When I press the play button unity crashes. the screen gets dim, and the play button turns grey (indicating that it is trying to start, usually thers is a little lag), but it never continues to change to the blue color (indicating that the game is now running). Here is my code.`var left : GameObject; var right : GameObject; var canspawn = true;

function Start () { print("started"); if(canspawn){ spawn(); } } function Update () {

}

function spawn(){ if(canspawn){ var thing : GameObject; var pice = Random.Range (1, 4); print (pice);

     if(pice ==1){
     thing = forward;
     }
     if(pice == 2){
     thing = left;
     }
     if(pice == 3){
     thing = right;
     }
 var nextpiece = Instantiate (thing, transform.position, transform.rotation);
 nextpiece.BroadcastMessage ("cantnorth");

} }

function cantnorth(){ canspawn = true; spawn(); }

function cantsouth(){ //canspawn = true; //spawn(); }

function canteast(){ canspawn = true; spawn(); }

function cantwest(){ canspawn = true; spawn(); } `

I know from testing that where everything breaks is in the Spawn() function. When i comment it out, that whole thing runs fine. If anyone see's anything i did wrong, or anything I could do better, please tell me. Also if you have any knowlege of why crashes even happen in unity, I would love the help. Thanks a lot!

Comment
Add comment · Show 3
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 liamcary · Feb 26, 2013 at 06:14 AM 1
Share

I'm not 100% I'm reading this right, but are these "forward", "left" and "right" objects using the same script? If so, the spawn script is infinitely recursive. By instantiating another "thing" in the spawn script, you're calling the new instance's Start function, which then calls the Spawn function, which then instantiates another object that does the same. It's essentially an infinite loop. Infinite loops will always crash unity

avatar image Zack-Londres · Feb 26, 2013 at 05:32 PM 0
Share

$$anonymous$$aybe, but I have had older versions of this code that went on infinantly. So I'm not totally sure it is that problem. I'll try that tho and see if I can come up with anything that will stop it from looping infinitely. Thanks for the input!

avatar image rednax20 · Feb 27, 2013 at 02:47 AM 0
Share

If you wanted it to loop infinintly you can ad yield WaitForSeconds (0.01) I find this will make unity run as fast as it can without crashing on start-up, I used this to make a fast rotating stick. Sorry if thats not what your trying to do.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MickM · Feb 27, 2013 at 01:37 PM

As in the comments, you are spawning an infinite amount of objects, this means that you will always run out of memory eventually which is why it is hanging. Currently there is no time that can spawn will ever be false (and you are never calling any function apart from cant north either)

Even if you add the delay as suggested, it will eventually still crash because you will keep spawning new objects forever (ie. until you run out of memory which will kill it!)

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

12 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 avatar image

Related Questions

Android game shuts down but doesn't crash on startup 0 Answers

Unity Editor has stopped working" in Windows 8 0 Answers

Unity Editor Crashes Upon Startup 0 Answers

Android Game crashing when collecting collectibles 0 Answers

Unable To Understand Android Crash : android.view.ViewGroup.offsetRectBetweenParentAndChild 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