- Home /
Get_GameObject non fatal error reoccuring
I have many scripts that use the 'get_GameObject' function, and errors like these keep appearing.
ArgumentException: get_gameObject 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. playerhealth..ctor () (at Assets/scripts/playerhealth.js:2)
get_gameObject 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.
UnityException: You are not allowed to call this function when declaring a variable. Move it to the line after without a variable declaration. If you are using C# don't use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function. playerhealth..ctor () (at Assets/scripts/playerhealth.js:2)
They don't Obstruct gameplay as far as I have noticed, but they do keep coming up in the console and it's becoming frusterating. Is there a different function i can use, or any way to remediate the errors?
Answer by Vandarthul · Apr 28, 2014 at 03:34 AM
Check this: http://answers.unity3d.com/questions/31429/argumentexception-getvalue-can-only-be-called-from.html
I believe you are assigning a value when declaring a variable on your class. Declare your variable first, and assign it on your Awake() or Start() function if that is the case.
Your answer
Follow this Question
Related Questions
error CS0118: `New_Career.Fame' is a `field' but a `type' was expected 1 Answer
Weird GetComponent error 2 Answers
Raycast to Disable Script 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Dataset is null 1 Answer