Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WWW: Can't load textures from remote paths

Discussion in 'Scripting' started by Elandir, Nov 22, 2017.

  1. Elandir

    Elandir

    Joined:
    Feb 9, 2014
    Posts:
    32
    Hi there.

    I need to load textures at runtime from external paths. I'm using WWW like this:

    Code (CSharp):
    1. Texture2D tex;
    2.         tex = new Texture2D(4, 4, TextureFormat.DXT1, false);
    3.         WWW www = new WWW(urlToLoad);
    4.         yield return www;
    5.         www.LoadImageIntoTexture(tex);
    6.         Renderer rend = GetComponent<Renderer>();
    7.         rend.material.mainTexture = tex;
    So far it's working as expected if urlToLoad is pointing to a image located into a website (e.g. urlToLoad = https://docs.unity3d.com/uploads/Main/ShadowIntro.png) and if it's a file in my local machine (e.g. urlToLoad = d:\ShadowIntro.png).

    I need to load the texture from a different pc shared folder in the same network but is not working. I tried some different formats to use as urlToLoad:
    • "\\PC_Name\SomePath\ShadowIntro.png" (as in the file browser).
    • "file://xxx.xxx.xxx.xxx/SomePath/ShadowIntro.png" (being xxx.xxx.xxx.xxx the image host ip. This was promising as I can put the ip+path+filename into my internet browser and the image is loaded)
    • Variations swapping slashes/backslashes, using file:///, using double slashes instead single.
    No matter what I try, the texture set into my renderer is a red question mark which, I guess, means that the texture couldn't be loaded though there is no error in my console.

    Can someone give me a hand with this, please?

    Thanks!!
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    Have you tried file://PC_Name/SomePath/ShadowIntro.png
     
    karl_jones likes this.
  3. Elandir

    Elandir

    Joined:
    Feb 9, 2014
    Posts:
    32
    Yes and it's loading the 'red question mark' texture in Unity. Just to be sure about the path I pasted it into my internet browser and the image is loaded there so the path itself seems to be correct.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    You need to pass the URI, not path to WWW. And do check for error in WWW, it should tell you when the uri is incorrect.
     
  5. Elandir

    Elandir

    Joined:
    Feb 9, 2014
    Posts:
    32
    Thanks Aurimas but I already tried the uri and it's not working, neither having any www error. :(

    As workaround I'm copying files from remote machine to local and loading from here. It makes the trick but it's far from good so I will appreciate any help with direct loading from remote machine ;)
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    Can you paste the exact URI for remote location?
     
  7. Elandir

    Elandir

    Joined:
    Feb 9, 2014
    Posts:
    32
    The exact path is \\PC_name\SharedData\MRTeam\Temp\TestImage.PNG

    I was using "file://PC_name/SharedData/MRTeam/Temp/TestImage.PNG" and getting the question mark texture instead mine.

    I've been doing some random test and just tried "file://///PC_name/SharedData/MRTeam/Temp/TestImage.PNG" (the very same string but with five '/' instead two) and now its working properly.

    I guess the difference is pretty obvious but I'm not used to work with remote machines and URIs. I really would appreciate if you could leave here a brief commentary about why ///// works and // doesn't.

    Cheers!
     
  8. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    I've been recently fixing this. So it goes like this:
    \\PC_name is actually a directory name, file URIs in general are local, but Windows network shares are supported, but they act as directories, only for URI backslashes need to be replaced by forward slashes, so you get //PC_name as directory name.
    Now file:// is the URI prefix, which is followed by host name (can be and in this case is empty), followed by slash and followed by directory (//PC_name in this case), hence 5 slashes. It would also work with 4, but that's more an exception.
     
    Elandir likes this.
  9. Elandir

    Elandir

    Joined:
    Feb 9, 2014
    Posts:
    32
    Ah, ok. now it makes sense.

    Thank you very much!! :)