- Home /
Find can only be called from the main thread
Hi, i'm having two errors i can't seem to fix.
It's:
Find 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.
and:
ArgumentException: Find 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. Colliders_overkant..ctor ()
Here is the code: using UnityEngine; using System.Collections;
public class Colliders_overkant : MonoBehaviour
{
bool overkant_active = true;
GameObject personage;
void Start () {
personage = GameObject.Find ("Speler");
}
void Update () {
}
void OnTriggerEnter ( Collider collider )
{
if (collider.tag == "Speler")
{
if (overkant_active == true)
{
Debug.Log ("Overkant");
personage.transform.Rotate (180, 0, 0);
overkant_active = false;
}
}
}
}
I suspect that the problem isn't in the code you've posted, it's that an object of that type is being created on a thread other than the main one. How and where are you instantiating these?
I think that's true. Please post the code that does instantiation of GameObjects to which this $$anonymous$$onoBehaviour is attached.
Indeed pb seems to be somewhere else and of this kind:
public class ClassWithProblem:$$anonymous$$onoBehaviour{
GameObject obj = GameObject.Find("Object");
void Start(){ }
}
You seem to be calling a method when declaring the variable.
Your answer
![](https://koobas.hobune.stream/wayback/20220613181827im_/https://answers.unity.com/themes/thub/images/avi.jpg)