Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

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,596
    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:
    71
    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.