Saving and loading problem on android only

Hello everyone,

I’m using the attached save system in my game (1.png).
I have this system in 3 blueprints in my game scene which are going to be saving/loading data somewhere during run time.
They’re always on the “Event begin play” and “Event Construct” nodes.

When I need to save a value I use (2.png).
When I need to load a value I use (3.png).

and It works fine… In editor and development builds.

Now in shipping builds it’s a whole different story.

First of all I have it it so the game is in one apk file and I have the “Use ExternalFilesDir for UE4Game Files” Option unchecked since
I found it to be very prone to exploitation from the player, I also wanted the saves to be persistent through uninstalls.
I added the following permissions to the “Extra Permissions” Section of the Advanced APK Packaging menu:
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_EXTERNAL_STORAGE
android.permission.WRITE_INTERNAL_STORAGE
android.permission.READ_INTERNAL_STORAGE

I also added the to the android manifest manually just in case.

If I build my APK as a development build, everything works fine, the APK asks for external storage permission on installation and the saving and loading work fine.
When I try building my APK for distribution though the APK does not as for any permission and the saving and loading don’t work, I then go inside the app permissions in my phone’s settings menu and manually grant the game storage permission which makes the menu scene able to “sometimes” save and load a value or two, however the game scene is still unable to save/load anything.

I’ve been pulling my hair out on this issue for a while, testing it on multiple devices and trying a bunch of different solutions that proved fruitless such as trying the “Use ExternalFilesDir for UE4Game Files” option.

at the moment I’m at my wit’s end and don’t have a clue where to go from here, without this feature I really don’t have a game, so any help you can provide my with is very very much appreciated.

Thanks in advance.

Very strange it works on Development builds but not Shipping builds… which Android SDK versions do you have for min, target, and which NDK and SDK versions do you build against?
Do you actually see the save game file on the device?

This option “Use ExternalFilesDir for UE4Game Files” is required by the way if you’re targeting SDK version greater than 23 (which will be required from Nov. on) and you want the saves to remain on app updates :wink:

My min SDK version is set to 9 and the max is set to 26, my SDK API level & NDK API level are both set to “latest”… I see the save file indeed if I choose the “Use ExternalFilesDir for UE4Game Files” and I can open it with a text editor and see the values inside but same problem the values get set in the menu level only, this is driving me up the wall to be honest.

I don’t really mind having “Use ExternalFilesDir for UE4Game Files” on anymore just as long as the save system works because my game completely relies on it to function properly and I don’t really want to redo the whole game in a different engine :frowning: … I really hope there’s a solution to this. Thank you either way for trying to help.

You say it works in the menu? Then it must be in the other levels where you call the save game is not done correctly in the blueprints as I’ve no issues using the save game accross different levels.

Also I would move the save logic out of the pre-construct event into something a bit later like begin play in case that is causing the issue. Also did you try cloning the same BP logic from your menu BP in the other levels to see if that works.

I’ve copied the above nodes to all the blueprints that have variables that I need saving, some of those are executed using in level triggers as apposed to the pre-construct event and even those still don’t save, I’ll try replacing all the pre-construct events with begin play events and see if that helps in anyway and post back the result.

Update:
Right now all my save instance and save data definitions are in the event begin play for game objects and event construct for widgets.
Unfortunately the problem still persists, save system works well in editor, doesn’t work in packaged android build.

Did you find a fix for this? same issues on 4.20

Austinlele, Unfortunately I haven’t been able to find any solution to this problem I even posted the issue on unreal answers here:

https://answers.unrealengine.com/questions/827816/saving-and-loading-problem-on-android-only.html

and haven’t received any answers on it yet, I’m not sure where to go from here and am unable to publish my game in its current state.

I thought about using a third party plugin as a workaround but there aren’t any free ones and third party plugins usually come with their own share of problems and often their developers give up on updating them to the latest engine version and they become unusable.

I may just migrate to another engine and redo the whole thing there.

change target api to 21 or below then test game…i was cratching my head all over night until i compared my code with some old project i did…in that project save function works fine so i compared its project settings and everything, only difference i found was target api…when i changed it from 26 to 9 it worked fine…still cannot upload my apk to playstore as it requires app to target latest api

I have exactly the same problem. As soon as I set the Target API to a value greater than 21, saving will stop working. (My version UE 23)

Saving works fine for me. Don’t lose hope. Make sure Use ExternalFilesDir for UE4Game files is enabled in the APK Packaging section. If it still doesn’t work, try creating a fresh project and migrating your content folder. Try copying your project settings manually.

If that doesn’t work, try making sure your android SDK and such are properly configured. Excluding the android APIs, make sure you only install what codeworks 1R7u1 installs. Then make sure the appropriate APIs are installed. For example, my min is 19 and my target is 28. So I have All APIs from 19-28 installed. Don’t know if that is necessary though.
In your project settings, make sure to set the NDK API Level in the SDKConfig section to android-19, and set the SDK API Level to latest.

1 Like

So. The android-sdk-windows update helped me. I don’t know why, but as soon as I updated it, SaveGame started working for all projects Android. I think it was just a flaw (Android sdk). I note that when updating, I only updated what the program itself offered me. Oh yes, I also updated the entire Extract folder.

after a lot of searching this f***** s*** I’ve found a solution for my case.
I wanna post it here so it may help someone, for anyone causing this problem with android he can check his app permissions in phone settings he may find that the application has storage permissions denied so change it to allow.