- Home /
ArgumentException: get_value can only be called from the main thread
Hi,
I have just converted a project from Unity iPhone 1.7 to Unity 3 Pro. I am getting this exception when I run the game:
ArgumentException: get_value can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. TankMovement..ctor () PlayerMovement..ctor ()
Double clicking the error message doesn't take me anywhere in the code. It looks like the error is complaining about a constructor, but I haven't specified any in those classes, and there aren't any other parent classes other than MonoBehaviour. I also went so far as to comment out my Start methods, and all the contents of any setXxxx methods from those classes, but nothing changed.
I know this is a pretty open ended question, so sorry for that, but does anyone have any insight into what this error really means, and where the problem is likely to be situated (certain kind of functions for example)?
The above mentioned classes are both C#, as are most my code.
Many thanks,
Pete.
Answer by Mike 3 · Oct 25, 2010 at 06:27 AM
My bet is it's referring to you assigning to a member variable - the code there will be run at constructor time
e.g.
public class Whatever
{
private bool myBool = AnotherClass.value; //throws your error
}
It sounds like you need to look for use of the value property from the compiler warning
Either way - stay clear of calling properties, functions or creating new objects with member variables in monobehaviours, you'll get weird runtime errors (and possibly editor errors)
$$anonymous$$ike you are spot on. I was doing "protected float soundDelay = Random.value * 10;" so I put that into the Start method and that solved it. Thanks a lot!
Thanks, It helped me too getting to the bottom of this problem. I was doing something similar in constructors.
Answer by ouyangnengjun · Apr 27, 2013 at 12:49 AM
不懂英文真悲剧!我是主摄像机的一个脚本上的Start方法里面调用socket获取起基本数据,数据是全部正常获取了!不过获取之后就报这个错误了!
這問題在兩年前已經被解答了,所以現在應該不再會有任何活動,也不太可能會有人回覆你的問題。
而且在這,無論你的母語是華語、西班牙語、日語、俄羅斯語等等,大家溝通時都使用英文。
而且,你有求於人,你可不能要求別人來看懂你在說些什麼。
請你盡量使用英語,你也可以使用翻譯工具和我們溝通,我們應該會看得懂。
A translation of the conversation:
ouyangnengjun
It is a pity that I can't speak in English. I have script on my main camera, I use a socket to grab the data in Start()
, and I got the data without any problem. However, after that, I get the same error.
me
The question is answered 2 years ago, so there should be no activity here anymore, and it is quite unlikely that anyone will reply to your question.
Furthermore, in UA, regardless of your mother tongue: Chinese, Spanish, Japanese, Russian etc, everyone here uses English when they communicate with each other.
And you are the one with the question, you can't expect people to put in extra effort to figure out what you are talking about, you have to make it understandable for them.
Please try to using English, you can use translation tool when you communicate with us, we should be able to figure out the meaning of your sentences.