Create an asset bundle from Sprite Packer Texture

Hi everybody,

i put some sprite in a folder and tag them by script. After that i call the Packer to rebuild atlases. Thats working fine.
Now i want to store the resulting atlas texture in an asset bundle but this is not possible.
I can access the Texture2D of the atlas but this not readable so i can’t copy it to a new Texture2D to store it. Also it is not possible to create a new asset from the texture because it is already an asset. Also i can’t access the TextureImporter of the texture because the asset path is an empty string.

Does anybody know how i can access the texture of the sprite packer and put it in an asset bundle so i am able to reload it from web?
Or does anybody know how to open the cache and extract the texture so i can store it in another folder?

Thanks for help

If anybody is needing this later: i finally found a working solution.
After i imported the sprites and repacked the sprite packer i do the following things:

  • Create a new Texture2D with the same height and width like the atlas texture you got with Packer.GetTexturesForAtlas(atlasName)
  • Set all Pixels of the new texture to be transparent
  • iterate to all imported sprites and get their UVs with SpriteUtility.GetSpriteUVs(sprite, true) and save the position rect of the sprite on the atlas and store it to SpriteMetaData
  • also make sprite readable and read all pixels of it and set them to the new texture at the previous gotten position
  • apply new texture and save it with File.WriteAllBytes and EncodeToPNG
  • refresh assetdatabase
  • get texture importer of the new texture and mark it as multiple sprite and set the SpriteMetaDatas array to spritesheet
  • finally set assetbundle name and reimport the asset

Hope this helps you. I anyone needs the code, contact me.