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 Peter Paulsen · Feb 26, 2010 at 11:34 PM · prefab

unity freezes when prefab is loaded into game

I looked around the web and I couldn't find this exact problem so I'm going to go ahead post the questions and hope someone has an answer for it.

This is my problem I have a prefab of an AI character,the prefab has code attached to it for pathfinding as well as basic character control. I can get the character to go between two predefined waypoints. The problem runs into when I try and make random waypoints for it to go to. let's say I have eight waypoints and I wanted the AI to go to four of them and I want those four to be chosen randomly. the code I wrote for this works perfectly fine if the object is already in the game prior to runtime. But if I make a prefab of this object unity crashes the moment I click run. I took out the random waypoint script and tried running it again, it worked perfectly fine for all predefined waypoints but the moment I wanted to choose one randomly the unity freezes. I don't have an error message to show you guys because it freezes before can make an error message. No show you the script that's causing the game to freeze and I love to know if you guys have any alternative ideas or ways of fixing this problem.

waypointLength = waypointAll.Length;

 for(int loopnum = 0; loopnum < CreatAI.HowManyWaypoints; loopnum++){        //this is for how many waypoints will be created
     Loopstart:
     num = Random.Range(0,waypointLength);   //creates a random number between zero and how many waypoints there are

     for (int waypointTest = 0; waypointTest < CreatAI.HowManyWaypoints; waypointTest++){        //this is the integer for the waypoint test loop
         if (Waypoint[waypointTest] == waypointAll[num]){
             goto Loopstart;     //if it fails then the two waypoints are the same if so go to loopstart and redo the test                   
         }
     }
     ObjectNumber[loopnum] = num;                    //makes the object number the same as the waypoint that way if the 3rd stop is going to object 7 the AI knows that
     Waypoint[loopnum] = waypointAll[num];       //copies the waypoint information of the random waypoint to the new waypoint array, putting them in order
 }

waypointall[] is where the eight waypoints are stored. Waypoint[] is where the four randomly chosen ones are stored. If I take this part of the script out unity3D doesn't freeze but my AI doesn't go to the waypoints randomly like I needed to.

I've tried creating this script four different ways applying it to the prefab, I've even tried applying it to a global variable that the prefab accesses and the moment the prefab axes that global variable it freezes. I even had it where the prefab accesses a global variable that has already randomly chosen those four waypoints prior to the creation of the prefab. every way I've tried it freezes a moment that it tries to access these waypoints.

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

2 Replies

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

Answer by Jaap Kreijkamp · Feb 27, 2010 at 04:40 AM

The function can apparently hang. Unity is single threaded so if you make a function that can hang, unity, including the editor hangs. You could try adding Debug.Log output to see what's actually happening, but you'll have to check the logfile instead of the logwindow as the logwindow isn't updated directly and when unity hangs you won't actually see the logging since entering the function.

Comment
Add comment · Show 2 · 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 Peter Paulsen · Feb 27, 2010 at 09:08 PM 1
Share

alright. i decided that trying to make a prefab of my AI was just not working because i was also trying to add a timer event to it and whenever then timer event when off unity froze so ins$$anonymous$$d i made the prefab start in game and told it to not render tell the timer went off and that seams to work.

avatar image ericksson · Mar 03, 2010 at 07:26 PM 0
Share

Peter, you should post your last comment as an answer and mark this as the right answer to your problem.

avatar image
0

Answer by john 2 · Aug 10, 2010 at 11:10 PM

Well, either your computer processor is to slow, or try re-scripting 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

No one has followed this question yet.

Related Questions

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

Enemy prefab's script won't keep inspector-applied settings. 0 Answers

Static target in the srcipt for my Prefab 2 Answers

Unable to assign prefabs target at runtime 1 Answer

How do i Instantiate a prefab with specific assests included 3 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