Search Unity

get_dataPath can only be called from the main thread?

Discussion in 'Editor & General Support' started by zergmouse, Sep 30, 2010.

  1. zergmouse

    zergmouse

    Joined:
    Jun 30, 2010
    Posts:
    216
    What does this mean?

    Code (csharp):
    1. ArgumentException: get_dataPath  can only be called from the main thread.
    2. Constructors and field initializers will be executed from the loading thread when loading a scene.
    3. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
    4. 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.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    that meanst that if you use system.threading don't touch anything thats in UnityEngine / UnityEditor namespaces at all
     
  3. drhmiri

    drhmiri

    Joined:
    Jun 17, 2014
    Posts:
    76
    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,
     
  4. mokkbs

    mokkbs

    Joined:
    Apr 21, 2013
    Posts:
    2
    Some where in your code, you are calling

    Application.dataPath

    in a Thread not the main/update thread. (Probably one your created)
     
    Marvin_Luo likes this.
  5. arche89

    arche89

    Joined:
    Aug 19, 2015
    Posts:
    1
    There is one not obvious case, error occur if you play it in editor:


    Code (CSharp):
    1.  
    2.     //This is cause:
    3.     private string ps_path = "URI=file:" + Application.dataPath + "/database.db";
    4.  
    5.     public Text txt_DataPath;
    6.     public Text txt_DbExist;
    7.     public Text txt_Error;
    8.  
    9.     // Use this for initialization
    10.     void Start()
    11.     {
    12.        //You should do this:
    13.         ps_path = "URI=file:" + Application.dataPath + "/database.db";
    14.     }
     
    ow3n, Marvin_Luo and drhmiri like this.