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.
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
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.