- Home /
Can function X be called while Update() is running?
I was wondering if a function in a script can be called (from another script) while the Update() in that script is running?
I want to know this because, my Update function modifies an array, that the function X also would like to modify, and I would like them to modify it one at a time. Currently I'm setting a boolean to true in the beginning of update, and to false in the end, in order to see if it is running.
I was just wondering if that is completely unnecessary, since unity is not multithreaded.
Answer by Daniel-Brauer · Nov 01, 2010 at 10:52 PM
Unless you explicitly use multi-threading (invoking threads, etc.) scripting in Unity is single-threaded. All callbacks, and even coroutines are executed serially.
In your example, Script.X() will never be called during Script.Update() unless Update() invokes the function at some level. You can safely remove the lock and your scripts should still work together.
Answer by IJM · Nov 01, 2010 at 10:38 PM
I guess that Unity uses multiple threads, but I think that two scripts are never runing in parallel (@ the same time).
So the the answer is yes. (Can function X be called while Update()...)
You confuse me a little. "two scripts are never running in parallel", and yet you say function X can be called while..? How is that possible?
Your answer

Follow this Question
Related Questions
System.Threading.Mutex not supported? 1 Answer
Multithreading Windows Store 0 Answers
Can't query ID3D10Multithread interface 1 Answer