1. All Unity Pro perpetual license customers: your special offer to subscribe is ready! Click here.
  2. We're running a survey about the usage of our graphics pipeline, help give us your feedback.
  3. Unity 5.6 beta is now available for download.
  4. Unity 5.5 is now released.
  5. Check out all the fixes for 5.5 in patch releases 1 & 2.
  6. Enter the Google Play Indie Games Contest in Europe. Read more about it here.
  7. Get prepared for the Tizen Mobile App Incentive Program! Read more about the upcoming program here.
  8. Enter the Microsoft Developer Challenge for a chance to win prizes. Read more about it here.

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
    Messages:
    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
    Messages:
    26,595
    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
    Messages:
    56
    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
    Messages:
    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
    Messages:
    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.     }
     
    Marvin_Luo and drhmiri like this.