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 · Mar 21, 2010 at 11:08 PM · errorprefab

ThreadCheck error when making Prefabs

I have this code for making an AI randomly every set amount of time. So every 5 seconds it makes a random prefab. Every 40 seconds it allows one more prefab to be made. I am doing this because I am making a Store sim and I want costumers be created and enter the store and the number of costumers allowed in the store slowly increase making the game harder over time.

The error Im getting only happens when I run the game in Unity3D and the moment the 5 seconds are up and its time to make a Prefab this error fills the Log and crashes unity.

m_ThreadCheck && !Thread::EqualsCurrentThreadID(m_ThreadID)

if I run the game as a EXE it runs fine making the AI every 5 seconds like it should. But after some time (anywhere between 20 seconds and 3 minutes of running the game) it crashes giving me an error saying to many threads. I dont code in c# so im not sure how my code is making a thread to begin with and why it is giving me that error. Here is the code:

private void creatAITimerevent(object source, ElapsedEventArgs e){ if(Time.timeScale != 0.0f){ counter ++; CapIncrease++;

     if(counter == timer){
         if(howManyAImade < howManyAIatOneTime){
             num = Random.Range(1,10);
             guyOutfit = (Random.Range(1, GuySet.Length)) - 1;
             girlOutfit = (Random.Range(1, GirlSet.Length)) - 1;

             if(num < 5){
                 Guy = (GameObject)Instantiate(GuySet[guyOutfit]);                       
                 Guy.name = SetNewName();        
                 GlobalObjectVariable.male++;
                 howManyAImade++;
             }else if(num > 4 && num < 9){
                 Girl = (GameObject)Instantiate(GirlSet[girlOutfit]);
                 Girl.name = SetNewName();
                 GlobalObjectVariable.female++;
                 howManyAImade++;
             }else if(num == 9){
                 BigGuy = (GameObject)Instantiate(BigGuySet);
                 BigGuy.name = SetNewName();
                 GlobalObjectVariable.bigGuy++;
                 howManyAImade++;
             }                   
         }
         counter = 0; //resets counter to start over
     }

     if(CapIncrease >= timeTellCapIncrease && (howManyAIatOneTime < howManyMaxAI)){
         howManyAIatOneTime++;
         CapIncrease = 0;
     }
 }

}

another thing is before I had it running in the Update() and that works never gives me a thread error or crashes the only problem with it is that I dont know how to make it create a AI every X amount of time and make it frame independent. The way it is written now if I have it in the Update it will make a AI ever seconds.

So my question is:

  1. how can I fix the code so that I can get it to not give me a thread error
  2. why is it giving me that error in the first place
  3. if I cant get it to work with a timer like it is not how do I make it work in the update() and make it frame independent

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 Peter Paulsen · Mar 22, 2010 at 12:15 AM 0
Share

just an update. i put my code back to the Update() and now its still giving me that error. i don't really get why it is giving me a m_ThreadCheck && !Thread::EqualsCurrentThreadID(m_ThreadID) error when i make the prefab. i have narrowed it down to the fact that it happens the moment the prefab is generated.

avatar image Peter Paulsen · Mar 22, 2010 at 12:36 AM 0
Share

Update 2.0:

i found that it was making the error because of some timers that were part of the AI (dont know why but thats another thing im going to work on) but im getting a new error

Thread::GetCurrentThreadID() != m_DeallocThread

its using the same code as above but thats the error that shows up when it makes the prefab

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Peter Paulsen · Mar 22, 2010 at 02:35 AM

so anyways after a lot of testing i found out that using a timer is what makes that error. dont ask why i have no idea. but when i put it in the Update() it works only problum is the frame rate changed depending on the computer and the game itself. so i put it all in a

 FixedUpdate();

so it looks like:

void FixedUpdate(){ if(!doTest){ if(Time.timeScale != 0.0f){ counter ++; CapIncrease++;

         if(counter == timer){
             if(howManyAImade < howManyAIatOneTime){
                 num = Random.Range(1,10);
                 guyOutfit = (Random.Range(1, GuySet.Length)) - 1;
                 girlOutfit = (Random.Range(1, GirlSet.Length)) - 1;

                 if(num < 5){
                     Guy = (GameObject)Instantiate(GuySet[guyOutfit]);
                     Guy.name = SetNewName();        
                     GlobalObjectVariable.male++;
                     howManyAImade++;
                 }else if(num > 4 && num < 9){
                     Girl = (GameObject)Instantiate(GirlSet[girlOutfit]);
                     Girl.name = SetNewName();
                     GlobalObjectVariable.female++;
                     howManyAImade++;
                 }else if(num == 9){
                     BigGuy = (GameObject)Instantiate(BigGuySet);
                     BigGuy.name = SetNewName();
                     GlobalObjectVariable.bigGuy++;
                     howManyAImade++;
                 }
             }
             counter = 0; //resets counter to start over
         }

         if(CapIncrease >= timeTellCapIncrease && (howManyAIatOneTime < howManyMaxAI)){
             howManyAIatOneTime++;
             CapIncrease = 0;
         }
     }
 }

}

and i just make the timer however many seconds it will be * 60 because i have it running 60 frames per seconds (at lest thats what it has come out to be)

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 Mike 3 · May 31, 2010 at 08:14 AM 1
Share

for future reference: Timers (in the System.Timers sense) use threads behind the scenes, so you'll generally get threading problems if you use them with unity functions. I'd have used a Coroutine for this, that way you can use WaitForSeconds between each call

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

Assign prefab to variable through script 1 Answer

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

SendMessage StartSending has no receiver! 1 Answer

Script not working (Java script) 2 Answers

Static target in the srcipt for my Prefab 2 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