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 /
avatar image
0
Question by Jason 2 · Apr 19, 2010 at 10:38 PM · waypoint

Having Unity lock up when running a path script

I am currently working on a game that requires me to have a gameObject follow a set path from one waypoint to another. However While I run the program the moment my script causes Unity to lock up. Here is my current script.

var roll : int = 5; var CurrentWaypoint : GameObject; var nextWaypoint : GameObject; var change : int = 1; var theWayPoints = new Array ("WayPoint1.1","WayPoint1.2","WayPoint1.3","WayPoint1.4","WayPoint1.5","WayPoint1.6","WayPoint1.7","WayPoint1.8","WayPoint1.9","WayPoint1.10","WayPoint1.11","WayPointF"); var i = 0;

function Update(){

 transform.Translate(Vector3(0,0,roll)* Time.deltaTime);

 PathOne();

 transform.LookAt(CurrentWaypoint.transform);

}

function PathOne(){

 while(i<theWayPoints.length)
 {
     if (Vector3.Distance (transform.position , CurrentWaypoint.transform.position) < change)
     {
         CurrentWaypoint = nextWaypoint;

         if (CurrentWaypoint == GameObject(theWayPoints[i]))
         {
             i++;
             nextWaypoint = GameObject(theWayPoints[i]);
         }
         else
         {
             Destroy(gameObject);
         }

     }   
 }

}

I have having it look for tags and just named gameobjects. But no luck. Any idea on what I did wrong?

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 Jason 2 · Apr 21, 2010 at 02:32 PM 0
Share

I have done that and what happens is that it reports the gameobject is lost and needs to have they way points stated. So I added

function Start(){
CurrentWaypoint = GameObject.FindWithTag("WayPoint1.1");
nextWaypoint = GameObject.FindWithTag("WayPoint1.2");

This enabled the gameobjects to know where to go when the game started. Problem is that it completely freezes unity before it can perform anything. A college and I believe it's due to the array. He and I tried various different ways around it from redoing the counter for i to completely removing it. Still froze / causes Unity to stop responding (so I have to force quit the program). Though I do like knowing about the Debug.Log. That will help more in the future.

avatar image Jason 2 · Apr 21, 2010 at 02:33 PM 0
Share

oh yeah forgot to mention that I corrected the PathOne fuction with the GameObject.FindWithTag so they would be uniformal.

2 Replies

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

Answer by Loius · Oct 08, 2010 at 02:42 AM

Let's simplify your while loop to just the things that deal with its exit case, i:

while( i < theWayPoints.length ) {
 if ( num1 < num2 ) {
  i++;
 }
}

If you enter the while loop while num1 >= num2 (i.e. while the character is farther than change from ANY WAYPOINT) it is an infinite loop.

Infinite loops are very very bad.

You might just need a "yield;" at the end of the while block.

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 Michael La Voie · Apr 20, 2010 at 12:24 AM

Start by adding some

Debug.Log("my message");

functions into your PathOne() function in many different places. Make sure you change the message to something different for each one you place.

I'd put them like this:

while(i<theWayPoints.length) { Debug.Log(1); if (Vector3.Distance (transform.position , CurrentWaypoint.transform.position) < change) { Debug.Log(2); CurrentWaypoint = nextWaypoint;

     if (CurrentWaypoint == GameObject(theWayPoints[i]))
     {
         Debug.Log(3);
         i++;
         nextWaypoint = GameObject(theWayPoints[i]);
     }
     else
     {
         Debug.Log(4);
         Destroy(gameObject);
     }

 }   

}

Run that code and see if you can see the debug log. Does it get stuck in an infinite loop? Do certain lines of code never get called? Please do this and update your answer.

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

A Question about GetComponent() (when accessing scripts).... 2 Answers

Confused about copying Lists! 1 Answer

Waypoints using a Switch... 2 Answers

waypoint ai script not going all the way to waypoint 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