Is it possible to save Texture2D or TextureRenderTarget2D in the game instance and save game class?

Hi,
I have a game with a photo system where the player can take pictures of his environment.
I store the photos in the player inventory, so if the player travels to a different level I would like to keep the pictures in the inventory.

I have tried with the SceneRender2D component, but it creates a TextureRenderTarget2D and I can’t seem to save it into the game instance or to a save game component.

I have tried with exporting the textures in a local png file, but then the player could totally mess with it and it could potentially break the game.

Is it possible to save Texture2D or TextureRenderTarget2D in the game instance and save game class?

Thank you for your help.

There are C++ functions to save and load pictures/textures.

However they need a bit technical parameters or picture is saved/loaded as garbage or format that i cannot find out.

I did save and load, but because of those settings, and that i could not find documentation (or i did not bother) i dropped idea.

But stuff is there in C++.

ps.
When you make mistake using those functions, and for some reason picture is not correctly loaded expect crash to desktop (because pointers are wrong). So make sure you have backups!

I suggest going for format like TGA or BMP, they have much easier header build up to save an image as bytes.

So I guess we cannot save textures or pictures in a save game object, but we have to save them individually.
Thank you for your answers.

1 Like