- Home /
 
Loading PSD files at runtime with WWW
I've had much success loading png files at runtime, but am running into problems when trying to load PSD textures[same exact directory/name except for a .psd extension] in the same manner.
 public void ReloadTexture()
 {
     string fileLocation = "file://C://Users//xxx//Desktop//skins//metal_a.png";
     StartCoroutine(WaitforWww(fileLocation));
 }
 
 IEnumerator WaitforWww(string fileLocation)
 {
     WWW www = new WWW(fileLocation);
     yield return www;
 
     Texture tex2d = (Texture)www.texture;
     Debug.Log(tex2d.GetType());
     MaterialManager.SMaterialManager.humanMaterial.mainTexture = tex2d;
 }
 
               This code runs exactly as expected, however if I change the fileLocation to point to metal_1.psd, I get a white/red question mark as the texture that's loaded into my material.
Do I need to handle psd files differently? Most of my research shows that I do not, but I cannot get a psd file to load with the same code that is successful with a png.
Thoughts?
Answer by Bunny83 · Sep 17, 2015 at 09:03 PM
Did your research take you to the docs? Because it quite clearly says:
The data must be an image in JPG or PNG format. If the data is not a valid image, the generated texture will be a small image of a question mark
At runtime you can only load either JPEG or PNG files. No other image formats are supported. Don't confuse the Unity engine (the runtime) with the Unity editor. The editor supports much more formats. That's most the time a matter of licenses. Unity bought a lot licenses to be able to support a lot different formats. However the runtime is something different. Because if they would include software that requires a special license you as developer would have to pay for it too.
If you need support for a certain format you need to find a .NET / mono compatible third-party loader library.
Thanks for your answer! I saw that originally, tried to use this code ins$$anonymous$$d and it didn't work :
 public void ReloadTexture2()
     {
         Debug.Log("here");
         string fileLocation = "C://Users//xxx//Desktop//skins//metal_1.psd";
         
         
         Texture2D tex = null;
         byte[] bytes;
 
         bytes = File.ReadAllBytes(fileLocation);
         tex = new Texture2D(2, 2, TextureFormat.ARGB32, true );
         
         tex.filter$$anonymous$$ode = Filter$$anonymous$$ode.Point;
         tex.LoadImage(bytes);
 
         $$anonymous$$aterial$$anonymous$$anager.S$$anonymous$$aterial$$anonymous$$anager.human$$anonymous$$aterial.mainTexture = tex;
         
     }
 
                  Then I tried to go back to the WWW means, and forgot that it only supported png and jpeg files. Thank you again.
Your answer
 
             Follow this Question
Related Questions
App crashing on Ipad - suspected memory leak. 1 Answer
Resources vs Asset Bundles vs file:// 0 Answers
Possible for a shader to have two decal slots? 2 Answers
heightmap or displacement map 1 Answer
NPOT for Texture2DArray 0 Answers