Casting to game instance always fails when packaging the game

Hi.

We have made a game, where we utilize a custom game instance class (made in blueprint), to store things such as music level, and graphics settings across levels. The project is setup to utilize the custom class, by defining it in the project settings:


. When performing casts to this custom game instance in any blueprint, everything seems to work fine when playing the game in the editor, or even as a standalone game. However, when packaging the game for shipping, the cast always fails. Is there anything that we are doing wrong, or is this simply a bug in the current version? A screenshot of one of the casts can be seen below:

1 Like

So right after posting this question I figured it out. Apparently there is a bug with the DefaultEngine.ini not updating correctly if files are renamed. The project settings thus showed the correct file name, but DefaultEngine.ini linked to the old file name, thus causing the build to be incorrect. Manually editing the file fixed the issue.

5 Likes

Massive thank you for posting this, wasted so much time trying to work out what was wrong with our game. What an irritating bug with UE4.

1 Like

Hi, I’ve tried every single answer I could find but nothing works. Whenever I play in editor the game instance works but when I launch on my android it doesn’t. Please help :confused:

1 Like

Never mind it turns out the .ini was missing a sub folder where the game instance was placed >__>

1 Like

Double massive thank you! My first level Blueprint casts to the game mode to set some variables, then spawns a camera and a bunch of other stuff, game would load, wrong camera, no HUD, figured out casting to my game mode was failing with a print string, found this thread, issue fixed, oh man, you are a life saver. Any word on this getting fixed? I had the same issue with 4.17

Thanks for posting this, I ran into the same issue with my project as well. Spent about 2 weeks trying to debug why my widget couldn’t communicate with my vrpawn when I packaged. This fixed it though!

You’re a f****** hero for posting this…Thank you…

Thanks you so much for this! It was making me crazy.

Bumping this because this bug still exists in 4.20

I am having an issue with my game instance only in a packaged game also and this may have something to do with it, but I do not understand the fix on this thread. Do you simply change the file name of the Game Instance within the content browser of the Editor so it doesn’t read the game instance with the same name from an old project? Or is there an .ini edit that needs to be made?

What a find! - Thankyou. - (4.20 project)

Real life saver :heart:
I’ve spent half a day trying to solve this issue!

When you change location your Game Instance folder in editor . you need to re select your current GI from the project settings/ Map&Modes

1 Like

Not just renamed, but moved. I moved my instance from one directory to another without renaming it, and it looks like it was pointing to the old directory.

Thank you for this post.
I got stuck still ver 4.25
Now I know how to fix it.

It is still an issue in UE5 Early Access. This fixed it.

This bug still exists in 4.26, thanks so much.

Greetings, posting this here as i have stumbled about a similar problem like this, but for me the path was always correct in the DefaultEngine.ini

I actually had in the .uproject file of the project the LoadingPhase as PostEngineInit. Chaging this back to Default worked. Depending if the loading phase is important, i’d suggest trying the other options for LoadingPhase, that can be found in Unreal Documentation.

Hope this also helps whoever stumbles with this problem again. And sorry for bumping this, as i have not found this answer in any other threads related to this.

For me the solution was to move Cast To Game Instance nodes
from my character Construction Script
to my character Event Begin Play