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.

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)

我也遇到类似问题!有人可以帮忙吗?

不懂英文真悲剧!我是主摄像机的一个脚本上的Start方法里面调用socket获取起基本数据,数据是全部正常获取了!不过获取之后就报这个错误了!