Hi,
I am having trouble with requesting storage permissions.
My game worked fine when I was packaging for API lvl 24. It saves my game with SaveGame node with no problem. Google doesn’t allow me to upload api 24 application. It requires at least api 29. I downloaded newer NDK version but some issues started popping up . It required some additional folders . After adding these from NDK 12 folder I managed to get it to build with the api 29 but when I installed the game on my phone I noticed the save game didn’t work.
I searched for a solution and found instructions on how to request app permissions but instructions were not consistent and my save game didn’t work no mater what I tried. It doesn’t work even if I manually give the app permission in settings. I placed nodes for the permission in GameMode class at the Event Begin Play.
To complicate even further I need to test in Shipping mode because Developer mode requests permition eather way. I don’t know if my code did that so no Developer mod and no Print String. (I am working arround this with a widget and text)
Additional settings images:
1 Like
SOLVED
I will explain what didn’t work in case someone is having issues with this.
I made a separate project just to test save game functionality with storage permission and, what would you know, the code works… Knowing this I returned to my project to solve the problem.
My code for save game was executed in GameMode_BP of the MainMenu_Map. This is a key think. This works fine when no permission is required but higher api levels require you to ask for permission so what happens when I do that?
In short flow of code gets messed up. My permission code was working, save file was created, but my Save/Load code was not being executed orderly. Now when the level is loaded it starts an override game mode so Level_BP and GameMode_BP code is being executed in parallel (I think). Since I am initializing all my actors in Level_BP many of the values are not passed in time. Further more there is a lot of back and forth between GameMode_BP and GameInstance_BP because my game mode was responsible for saving and loading data but game instance was responsible for actually keeping track of it during gameplay.
Enter my roommate, the savior. He advised me to do my save/load in game instance with the EventInit (executed on game initialization). Since game instance is pretty much the first to be loaded it will load data for rest of the game to use. And since it is a game instance i didn’t have to go back and forth by casting to game instance from game mode to preserve data and so on. Just access game instance as I usually would (cast, get game inst, get value).
Next problem. Even with all this save was inconsistent because of the way it worked. This function now played on EventShutdown. But as with any app on android my game was not being shut down on “Quit” or “Shutdown” buttons. It was sent to background and removed from recent apps tray. This doesn’t inform the app that it should quit it self.
To prevent data loss I implemented a ForceSaveGame custom event. It is called whenever I enter MainMenu_Map, when I close Settings, when I come back from CustomizationMenu and so on. There is a better way of doing this but let me explain.
ApplicationWillEnterBackgroundDelegate is a delegate that can be bound to any code and is called when a user goes to the home screen or switches apps. It, however, is called almost always. In my experience to get it to work you first need to send the game to background and come back to it. I assume that only then does it actually binds the event. Every next time it works whether you close it from recent apps or switch to a different app or go to home screen.
This is my code and my settings:
game instance
load
save
settings
1 Like