Cast To GameMode always fails

Hi, I would like to ask for some help regarding my issue.

In my GameState, I am trying to cast to my GameMode, but it always fails and I can’t figure out why. My function is supposed to set the “is Player In Game?” boolean variable to the same value that the “Is This An in Game Game Mode?” variable has, which is stored in “myGameMode”. The cast always fails, here is my Blueprint setup, I can provide more screenshots if necessary:

Thanks.

Make sure that myGameMode is set as the default gamemode under Project Settings > Maps & Modes.

2 Likes

Hi, thanks for your answer! I forgot to mention that it is!

I may figured out the answer to my own question. The Default Game Mode is myGameMode, however the level I’m using overrides it with InGameGameMode, which is inherited from myGameMode. I guess I have to cast to InGameGameMode itself and then it will succeed. I don’t even know why I wanted to cast to myGameMode, InGameGameMode has the boolean as well, in fact, the correct value I’m looking for is in the currently used GameMode, which is InGameGameMode.

Thanks for your suggestion, it led me to the solution!

2 Likes

Hi everybody!

I ran into something similar, so I thought I should ask for help here:
So I have put a SetPlayerCharacter into the map blueprint (I am working based on an RTS tutorial). When I debug I see that If execution gets to Cast to MyGameMode it will always fail. Here is my blueprint. This only works when Game mode is set to GameModeBase in project settings. In MyGameMode spawning doesn’t even start even though I have a MyGameMode class (2nd screenshot). I can provide more screenshots if necessary.

Thank you in advance!

In case this helps anyone…

You also need to check the World Settings to see if the GameMode is getting overridden by the setting there.

See the documentation for more about this.

2 Likes


In my code the cast to game mode always fails… Any ideas on how to fix it?
The game mode is “Puppet survival”… Don’t question it lol

First of all ensure you have correct GameMode setup in project settings and in WorldSettings overrides on level.
If that’s not the case, on CastFailed you can print GameMode class name with PrintString, maybe this will give you a hint.

ok, ill try it… Thanks!

Thank you, it worked for me (:smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.