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 RLin · Jun 23, 2015 at 06:35 PM · buildbugcrashontriggerenterobject pool

Endless Highway script CRASHES Unity!?

I am developing a car game, and I have a script that spawns a section of highway in front and a section of highway behind the player when they enter a trigger, and also places unused sections back into an object pool. The script works well, however, if the player enters the same trigger twice, Unity freezes for several seconds, and then crashes. It also crashes the build. Here is the script: using UnityEngine; using System.Collections;

 public class EndlessHighway : MonoBehaviour {
     public GameObject player;
     private GameObject me;
     private float fz;
     private Transform[] all;
 
     void OnEnable(){
         me = this.gameObject.transform.root.gameObject;
         all = me.transform.root.GetComponentsInChildren<Transform> ();
         for (var i = 0; i < all.Length; i++) {
             all [i].gameObject.tag = "Highway";
         }
          fz = me.transform.position.z;
     }
     
 
     void OnTriggerEnter(Collider other){
         if (other.transform.root.gameObject == player) {
             for(var i = 0; i < all.Length; i ++)
             {
                 all[i].gameObject.tag = "Don't Destroy";
             }
             GameObject[] highwaysToDestroy = GameObject.FindGameObjectsWithTag ("Highway");
             for (var i = 0; i < highwaysToDestroy.Length; i++) {
                 ObjectPool.instance.PoolObject (highwaysToDestroy [i]);
             }
             for(var i = 0; i < all.Length; i ++)
             {
                 all[i].gameObject.tag = "Highway";
             }
             GameObject highway1 = ObjectPool.instance.GetObjectForType ("endless highway", false);
             highway1.transform.position = new Vector3 (0, 0, fz + 1000);
             highway1.GetComponentInChildren<EndlessHighway>().player = player;
             GameObject highway2 = ObjectPool.instance.GetObjectForType ("endless highway", false);
             highway2.transform.position = new Vector3 (0, 0, fz - 1000);
             highway2.GetComponentInChildren<EndlessHighway>().player = player;
         }
     }
 
 }
 
Comment
Add comment · Show 2
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 Neilos · Jun 23, 2015 at 06:37 PM 1
Share

Have you tried debugging the problem? Which line of your script does the game crash on? And what is the state of the variables when it crashes? Do you get any error messages/logs?

avatar image RLin · Jun 23, 2015 at 06:49 PM 0
Share

There were no error messages or logs. However, I did find a similar question that stated that unity crashes when assigning tags in certain situations (specifically loops), so it could be related to that.

1 Reply

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

Answer by Xarbrough · Jun 24, 2015 at 09:33 AM

Usually, when something also crashes the built, it's not a bug in the editor. I would guess it runs in some kind of endless loop. Have you tried removing all statements from within your loops and replacing them with print? Comment out most of the logic and enable it bit by bit to narrow down where it crashes and if all loops are being terminated.

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 RLin · Jun 25, 2015 at 10:24 PM 0
Share

It turns out that it was getting stuck in an endless loop. I removed the for loop and changed only the tag of the transform root, while leaving its children untagged.

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

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

Related Questions

UnityException: Launching iOS project via Xcode4 failed. Check editor log for details. 1 Answer

Distribute terrain in zones 3 Answers

Crash in build when reloading level with a Sprite Renderer in the scene 0 Answers

Why after put ads unity game cannot open 1 Answer

MovieTexture will not play in Build - Black Screen 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