get_dataPath can only be called from the main thread?

What does this mean?

ArgumentException: get_dataPath  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.
Procedure..ctor ()

It points to a game object which only has one script on it. But it does not give me any real information on how to fix the problem. If it does, I can’t tell.

that meanst that if you use system.threading don’t touch anything thats in UnityEngine / UnityEditor namespaces at all

Hi Dreamora,
Can you please elaborate on this?
I get this error message when I build my Unity application into a standalone, but I have no clue where to look for the problem?
Thank you,

Some where in your code, you are calling

Application.dataPath

in a Thread not the main/update thread. (Probably one your created)

2 Likes

There is one not obvious case, error occur if you play it in editor:

    //This is cause:
    private string ps_path = "URI=file:" + Application.dataPath + "/database.db";

    public Text txt_DataPath;
    public Text txt_DbExist;
    public Text txt_Error;

    // Use this for initialization
    void Start()
    {
       //You should do this:
        ps_path = "URI=file:" + Application.dataPath + "/database.db";
    }
3 Likes