# GameInstance constructed two times (android)

**URL:** <https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567>\
**Category:** Mobile\
**Tags:** gameinstance, unreal-engine, Android, question\
**Created:** [January 10, 2015, 6:29pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567 "2015-01-10T18:29:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dredok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dredok](https://forums.unrealengine.com/u/Dredok)\
**Post date:** [January 10, 2015, 6:29pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/1 "2015-01-10T18:29:18Z")

</div>

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:

> **[GameInstance is constructed three times](https://forums.unrealengine.com/showthread.php?55855-GameInstance-is-constructed-three-times)**
>
> Hi, I use GameInstance to hold some services and I thought it is constructed only once. But I see the GameInstance is actually constructed three times. Is this intended? How should I approach this problem then? I want to initialize my services only...

**Please, note this only happens on Android Devices. Not on PIE.**

engine version: 4.6.0

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [January 15, 2015, 4:09pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/2 "2015-01-15T16:09:21Z")

</div>

Hey -

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?

Cheers

---

<div class="post-metadata">

**Author:** ![Dredok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dredok](https://forums.unrealengine.com/u/Dredok)\
**Post date:** [January 15, 2015, 4:31pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/3 "2015-01-15T16:31:21Z")

</div>

Hi,

I’m using an engine from GitHub based on 4.6.0 release (commit a56889f061d0d897f4bc3f1736afb27a0bf10358)

I do not have 4.6.1 currently so I can not test it.

---

<div class="post-metadata">

**Author:** ![Dredok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dredok](https://forums.unrealengine.com/u/Dredok)\
**Post date:** [January 15, 2015, 8:00pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/4 "2015-01-15T20:00:29Z")

</div>

So in your device the GameInstance is constructed only once with 4.6.1?

You did not reproduce it in 4.6.0 ?

With a simple Log I see the GameInstance is constructed twice see this copy&paste from my code:

```
USTPGameInstance::USTPGameInstance(const class FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
	, bMusicEnabled{true}
	, bSoundsEnabled{ true }
	, bDebugProfileEnabled{false}
{
	InventoryDB = ObjectInitializer.CreateDefaultSubobject<UInventoryDB>(this, TEXT("IventoryDB"));

	if (!HasAnyFlags(RF_ClassDefaultObject | RF_ArchetypeObject))
	{
		UE_LOG(LogTemp, Log, TEXT("Initializing InventoryDB from GameInstance path '%s'"), *GetPathName());
		InventoryDB->Initialize();
	}
}
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [January 15, 2015, 8:27pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/5 "2015-01-15T20:27:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [January 21, 2015, 8:55pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/6 "2015-01-21T20:55:09Z")

</div>

Hi ,

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.

Thank you.

---

<div class="post-metadata">

**Author:** ![Mattlauk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mattlauk](https://forums.unrealengine.com/u/Mattlauk)\
**Post date:** [January 23, 2015, 3:35am UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/7 "2015-01-23T03:35:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mattlauk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mattlauk](https://forums.unrealengine.com/u/Mattlauk)\
**Post date:** [January 23, 2015, 5:07am UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/8 "2015-01-23T05:07:23Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Mattlauk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mattlauk](https://forums.unrealengine.com/u/Mattlauk)\
**Post date:** [January 23, 2015, 5:08am UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/9 "2015-01-23T05:08:19Z")

</div>

Got it! [3 more characters needed…]

---

<div class="post-metadata">

**Author:** ![Dredok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dredok](https://forums.unrealengine.com/u/Dredok)\
**Post date:** [January 23, 2015, 5:10am UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/10 "2015-01-23T05:10:09Z")

</div>

Actually my issue has nothing involved with replication because my game is standalone.

---

<div class="post-metadata">

**Author:** ![Mattlauk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mattlauk](https://forums.unrealengine.com/u/Mattlauk)\
**Post date:** [January 23, 2015, 5:13am UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/11 "2015-01-23T05:13:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Dredok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dredok](https://forums.unrealengine.com/u/Dredok)\
**Post date:** [January 23, 2015, 5:16am UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/12 "2015-01-23T05:16:13Z")

</div>

I test this on an android device directly, so there is no Run Dedicated Server possibility.

My game instance is referred by several parts of my code but none of them construct it neither are involved in it construction.

It is constructed at some point in engine initialization and might be related only to android devices.

---

<div class="post-metadata">

**Author:** ![Mattlauk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mattlauk](https://forums.unrealengine.com/u/Mattlauk)\
**Post date:** [January 23, 2015, 5:17am UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/13 "2015-01-23T05:17:51Z")

</div>

I’ll see if I can reproduce. I’ll get back to you.

---

<div class="post-metadata">

**Author:** ![Mattlauk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mattlauk](https://forums.unrealengine.com/u/Mattlauk)\
**Post date:** [January 23, 2015, 5:19am UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/14 "2015-01-23T05:19:19Z")

</div>

Are you still using 4.6.0 release (commit a56889f061d0d897f4bc3f1736afb27a0bf10358) or using 4.6.1?

---

<div class="post-metadata">

**Author:** ![Mattlauk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mattlauk](https://forums.unrealengine.com/u/Mattlauk)\
**Post date:** [January 23, 2015, 6:07am UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/15 "2015-01-23T06:07:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dredok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dredok](https://forums.unrealengine.com/u/Dredok)\
**Post date:** [January 23, 2015, 8:52am UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/16 "2015-01-23T08:52:47Z")

</div>

I really appreciate your efforts MJLaukala’.

Why do you keep trying on PC?

I said this happens on android. There is no editor startup involved because there is not editor at all.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [January 23, 2015, 3:08pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/17 "2015-01-23T15:08:38Z")

</div>

Hey -

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.

---

<div class="post-metadata">

**Author:** ![Dredok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dredok](https://forums.unrealengine.com/u/Dredok)\
**Post date:** [January 23, 2015, 5:12pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/18 "2015-01-23T17:12:09Z")

</div>

I’m sorry but I’m really lost here. How can be this a valid point? Do you know that GameInstance is constructed by the Engine itself, right?

I’m not creating it at all! (and shouldn’t) i’m only using the one created by the Engine (well, actually two of them because of the bug)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [January 23, 2015, 5:33pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/19 "2015-01-23T17:33:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mattlauk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mattlauk](https://forums.unrealengine.com/u/Mattlauk)\
**Post date:** [January 23, 2015, 5:48pm UTC](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567/20 "2015-01-23T17:48:46Z")

</div>

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.

[Next page](https://forums.unrealengine.com/t/gameinstance-constructed-two-times-android/303567.md?page=2)
