Search Unity

WWW in background thread.

Discussion in 'Editor & General Support' started by jeffcraighead, May 12, 2011.

  1. jeffcraighead

    jeffcraighead

    Joined:
    Nov 15, 2006
    Posts:
    740
    Hi all, I'm attempting to use the WWW class to get a large XML file in a background thread. I get the following error:

    UnityEngine.WWW:InitWWW(String, Byte[], String[])
    UnityEngine.WWW:.ctor(String, Byte[], Hashtable)
    UnityEngine.WWW:.ctor(String)
    Walls:GetWallsFromServer() (at Assets/Scripts/Walls.cs:94)

    Not sure how to interpret that since it seems to point to an internal initialization problem. Is it not possible to use WWW outside of the main thread? If not, why is it this way Unity folks? This is the type of thing that should definitely be able to run outside of the main.

    Thanks!
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    You can not use anything from UnityEngine outside the unity thread in generally, so a no there (exception seems to be Debug.Log but thats likely more cause the OS or Mono handles the concurrent file accesses there). Reason is that Unity is not threadsafe!

    But you also don't need it for WWW as WWW is always in an internal workerthread, it does not run on the engines own thread.