Hello,
I am trying to call Application.LoadLevel(1); inside one event function.
This function lives in a class which inherits from MonoBehaviour.
When I call LoadLevel inside update or OnGUI it works pretty well,
but when I try to call it inside my event function it does not work.
Since I am using several threads, I would like to avoid sharing a variable between my MonoBehaviour and my other thread in order to change level.
Do you have any Idea how to change Level outside MonoBehaviour functions ?
Thank you very much !
Taz
It will only work on the Main Thead.
UnityEngine is not Thread-Safe at all.
You can sometimes use Debug.Log() (Except on iOS), but most other calls are going to crash when in another thread.
You’ll need to get back on the main thread to call Unity functions.
Edit: In even shorter form
LoadLevel() works anywhere on the main Unity thread. It doesn’t work from any other threads. Unity’s API isn’t designed for Multi-Threading.
Rather, they will silently fail. It used to be that they would randomly crash, but now they are just prevented from working. (Which is good, but an error message would be better.)
–Eric