Why is my Cast to Game Mode failing?

I have an actor BP, that in the construction script it cast to the game mode. I have looked around but I cannot see why it is failing. Can you not cast to the game mode in the construction script of an actor?

GameMode is only present on the server. Also, the construction script runs in the editor too. There won’t be a GameMode in that case either. It’s only created when the game is started.

Hi, i have the same issue currently, from what i’ve learned so far the cast to game mode is failing:

Always on clients. They dont have a game mode object.

Always in ViewPortEditor

It works in either event graph or construction script on server, but will fail until you actually play the game. So it works in construction script but will not show/execute in editor. Use gamemodes for server logic only.

You can use GameStates to cast them as they do get replicated on clients.

That’s strange because there’s a tutorial on Digital Tutors that tells you to place code inside the game mode so you’d imagine that you’d be able to cast to it from another blueprint. I haven’t finished watching the series but I ran into the same issue when I was trying something outside the scope of the tutorial.

Yes, that’s correct. The GameMode is only valid on the server.

I love seeing this echoed throughout a hundred answers without a single one actually helping to show how to accomplish it. I’ve now read through the first page of Google’s results and see “GameMode is only valid on the server” over, and over, and over. Not once does anyone offer up any advice on how a client can get something from the GameMode. Even a simple example like setting an integer.

2 Likes

It’s impossible to do on the client. The game mode never exists there. If there’s something the client needs from it, it must be replicated from the GameState object.

Make sure your game mode is not overridden in the world settings.