Saving an EncodeToPNG(); to disk at runtime?

So basically I am working on the basics of perlin noise terrain generators in unity. However, I can't seem to figure out how to save the finished PNG file to disk. This isn't about changing an existing image, it is about creating a new image. Here is the affected code so far.


      var byt = tex.EncodeToPNG();
      System.IO.File.WriteAllBytes("Assets/test.png", byt);

This is in javascript, by the way.

I can't see what could possibly go wrong with this code. I do the very exact same thing in my screenshot-taking script. However I do this in editor-time, not game-time. Have you tried to invoke this code while in the editor rather than when the game runs?

1 Answer

1

in my case it was easy:

had to use

Rect[] uvs = atlasTexture.PackTextures(textureList,0,2048,false);

instead of

Rect[] uvs = atlasTexture.PackTextures(textureList,0,2048,true);