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 HuskyPanda213 · Sep 02, 2014 at 09:33 PM · c#coroutinenode

Implement waiting but cannot use while() or coroutine?

I am creating a node based scripting system for my game, so when I need basic functionality I can just create it in the node-editor. I want it to work like the NodeGraph in CryENGINE, or the blueprint graph in Unreal 4. I have thought everything out, but there is one problem: I do not know how to implement a system that waits for all the input nodes to have completed their operation before the next one becomes active. Threading.Thread.Sleep freezes unity, while() freezes unity, and I cannot use coroutines because I am not using monobehaviour--I am using an abstract class that does not inherit from anything.

EDIT: Changed the name of the question, I mean't to say I tried using threads but it would make the editor freeze.

Comment
Add comment · Show 1
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 bubzy · Sep 02, 2014 at 09:48 PM 0
Share
 if(inputNode)
 {
 //do what you waited for
 }

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Tekksin · Sep 02, 2014 at 09:54 PM

Threading.thread.sleep sounds impossibly complicated, so I can only hope that my suggestion doesn't insult you, but why not just use a boolean?

Use a bool array and set the bool to true for each when the routine for whatever node is complete. The script will then read the node until that bool turns true. So you would have something like (JS)

 if(!bool[1]){
   //first node Active
   bool[1] = true;
 } else if(!bool[2]){
   //second node Active
   bool[2] = true;
 } //etc

Is there a reason why you wouldn't do something like that, or have I misunderstood the question?

And if you want an artificial pause, do something like

 if(bool[1]){
  //first node
  FakePause();
 } else if(bool[2]){
  //second node
  FakePause2();
 }
 
 function FakePause(){
   yield WaitForSeconds(1);
   bool[1] = false;
 }
 
 function FakePause(){
   yield WaitForSeconds(1);
   bool[2] = false;
 }

or you can of course do something like,

 aNumber : int = 0;
 
 if(aNumber == 0){
  //first
  FakePause();
 } else if(aNumber == 1){
  //second
  FakePause();
 }
 
 function FakePause(){
  yield WaitForSeconds(1);
  aNumber++
 }



Again, I apologize if I'm insulting you with this kind of solution, but I also may have totally read the question wrong.

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 kacyesp · Sep 02, 2014 at 10:00 PM 0
Share

"Threading.thread.sleep sounds impossibly complicated". That sounds like a very opinionated statement if you don't understand threads.

avatar image HuskyPanda213 · Sep 02, 2014 at 10:26 PM 0
Share

I can't use your solution Tekksin, I cannot implement yield WaitForSeconds. I am using a class that does not use $$anonymous$$onoBehavior. I also could not implement just if-else statements because it does not wait but checks ins$$anonymous$$d.

avatar image
0

Answer by kacyesp · Sep 02, 2014 at 09:58 PM

It's a shame you're not willing to use threads because that's totally the best solution for something like this. On a high level, you would just create a "barrier" that puts all threads except the last one to sleep using a condition variable. When the last node shows up, you wake up all the threads.

A while loop could also work, but it's probably a bit slower. It shouldn't lock up unity though unless it's an infinite loop.

Comment
Add comment · Show 3 · 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 bubzy · Sep 02, 2014 at 10:25 PM 0
Share

while loops are dangerous for that very reason. if the condition isn't met, or is ambiguous then you're looking at a lockup

avatar image HuskyPanda213 · Sep 02, 2014 at 10:27 PM 0
Share

I mean't to say that threading.sleep locked up the whole game. I also don't want several threads if I have more than one node. To the while loop, I implemented while(!input); and then did code after it, but it just froze.

avatar image kacyesp · Sep 02, 2014 at 10:31 PM 0
Share

Sounds like you just need to debug it then. For while loops that are potentially infinite ( and in your case it's more than "potentially" infinite ), I would add a "safety net". Just add a counter variable to your code that counts the number of iterations your while loop has executed. If it has iterated more times than what you'd expect in the worst case scenario, then break out of the loop. You may also want to print out some Debug statements to show why you were in the loop for so long. That would aid you in debugging why the loop is infinite.

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

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Rotate an object using Quaternion.RotateTowards() inside a Coroutine? 1 Answer

How do i make sure an Object is initialized before using it ? C# 2 Answers

Can't get basic skill to work right(C#) 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