Archive 17/01/2023.

Android, how to Save/Load data from/to internal storage?

TikariSakari

Hello, I am new to urho3d, well pretty much just installed it, and it really seems quite nice engine. Sadly there aren’t that many tutorials around and the only guidelines would be the samples I think?

I was wondering is there something for save files? Like lets say I want to save progress on my game on android, is there some premade libraries for it? Like I would prefer to use internal storage to use save files for a game, where should I start digging this stuff? I tried to google around, but couldn’t really find anything.

Thank you in advance.

Edit: I think this question should have been inside support forums, sorry for posting it in a wrong place.

jmiller

Welcome to the forum TikariSakari :slight_smile:

The sample programs save scene data to XML file (“F5 to save scene, F7 to load”)
18_CharacterDemo does saves (serializes) data external to the scene.

You might find useful: XMLElement and XMLFile
urho3d.github.io/documentation/H … ement.html
urho3d.github.io/documentation/H … _file.html

or the File class
urho3d.github.io/documentation/H … _file.html

HTH

cadaver

As for the directory where to save, try either FileSystem::GetUserDocumentsDir() or FileSystem::GetAppPreferencesDir(). I don’t remember personally trying to save data on an Android application, so your mileage may vary.

Mike

I’m using FileSystem::GetUserDocumentsDir() and it works great.
Note that user documents dir is located at /data/data/com.github.com.urho3d/files/ (unless you modify the manifest otherwise).
FileSystem::GetAppPreferencesDir() is for desktop.

You can also refer to this post http://discourse.urho3d.io/t/android-writing-in-resource-cache/88/1.

cadaver

Had a vague memory that we’d ported code from SDL hg to handle SDL_GetPrefPath() on non-desktop platforms, but apparently remembered wrong. Anyway, there are also SDL Android specific functions SDL_AndroidGetInternalStoragePath() & SDL_AndroidGetExternalStoragePath(), but like Mike said GetUserDocumentsDir() should work fine.