I think its a bug … the GameInstance is being constructed two times instead of once. And its stated in several places that it should behave like a Singleton …
I have also posted this on forum thread:
Please, note this only happens on Android Devices. Not on PIE.
Are you using the source code version of the engine from GitHub to package your project or the binary version from the launcher? If you’re using the launcher, does the same behavior occur if using 4.6.1?
I am having difficulties reproducing the game instance being created twice when trying to package 4.6.0 for an Android devices. If you get the chance try packing in 4.6.1 and let us know if you still see the same behavior.
We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.
I am having the same issue. It creates two when running a dedicated server. The only issue with this is that it is impossible to tell when it’s server side or not. I have some custom network stuff that needs to persist across maps and modes but I can’t figure how how to reliably get the role.
A game instance is created for every client and on the server(if dedicated). I do not know if it is possible replicate it as it is not an actor. But if you have things that need to be setup once on the server, such as a FTcpListener, you can create a function and call it from GameMode using a ROLE == ROLE_Authority check and then setting an IsInitialized boolean flag to ensure that you do not call it again. Be sure to check out the First Person Shooter example that is available in the launcher under the learn tab!
Under the play drop down menu, do you have “Run Dedicated Server” checked? That’s about the only thing that I can think of. If not, can you post all code referencing your game instance?
It seems to be working normal for 4.6.1. However, the constructor [YourGameInstance::YourGameInstance(const class FPostConstructInitializeProperties& PCIP)] is called when when the editor starts up. this is because the engine needs to create a default object. But GameInstance does have a Init() function that you can override that should only be called when the actual game starts up.
You didn’t supply much information. As a result, it makes it extremely difficult to troubleshoot. Regardless, I feel fairly confident that this is the issue you are having.
MJLaukala’ does have a valid point of needing to understand how your game instance is created. Are you creating it in code or with blueprints? Could you post a screenshot (if using blueprints) or the code for the game instance? This will give us an idea of how it’s being created and what might be causing it to be constructed twice.
In the editor, if you go to Edit->Project Settings there is a category for Maps & Modes. At the bottom of the Maps & Modes menu is where the game instance to be used for the project can be set. For your project, is this set to the default (likely just called GameInstance) or have you changed it to something else? In blueprints it’s possible to create a custom game instance other than the default by choosing New Blueprint and setting the parent to GameInstance. This created blueprint can then be set as the game instance in the project settings.
If you are using a custom instance as described above then it is important to know how it was setup and what it was doing. If you are using the default game instance it is important to know what was changed/added to it for your game.
Because that’s the only way to reliably test your problem given the lack of information supplied. I asked earlier that you post code and you still haven’t. I’m just going to assume that your code/blueprints are the issue. Without any further information, ie code/screenshots, you are going to have to find and fix the issue yourself. There are many reasons why your game instance constructor is called more than once. Without information, people who want to help are forced to basically guess. If you haven’t solved it by now and still want help, you should really consider posting code/screenshots.