1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. Unity 2017.1 beta is now available for download.
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  8. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    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:
    57
    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:
    1
    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.