How do you cast to the gamemode

You’re casting it correctly.

Please note though, your Game Mode object is ONLY available (not null) on the Authority machine. This means when you are playing multiplayer, if you call GetGameMode() on the client it will return NULL therefore the cast will fail.

What is the purpose of this data that you are accessing? Perhaps it makes more sense to store it in the game state which is accessible to all machines.

Hey all,

I have data on my GameMode that Im trying to access within an actor blueprint but no matter how I try I cannot cast to the gamemod, even the documentation wasn’t helping, Please can you help me? how do you cast to the GameMode?

Many Thanks

Andrew Booth 3D

Thanks for your reply,

It isn’t going to be multiplayer but single player,

the stuff im storing in there is like variables for pick up number float, maximum number pick per pick up ect for bronze, sliver and gold.

e.g 10 bronze equal a sliver coin

Would it better to store in the character?

many thanks

Andrew Booth 3D

Did you configure your project/level to use your MyGameMode instead of the default GameModeBase? Go to Edit > Project Settings > Maps & Modes and check the drop down for Map Mode.

More importantly, what does GetGameMode return? Press F9 on your Cast node and it will set a break point. The next time you run your game it will pause script execution at your break point and you can hover the mouse over the Return Value for GetGameMode and it will tell you the object type of the value.

Your game mode should store the rules of the game. So don’t store player inventory in the game mode. For example you could store a variable in your game mode that tells the player’s how much inventory they can hold. This way you can potentially have multiple game modes that have different inventory max carry limits.

A little heads up on what’s persistent in variables. Variables inside your character are persistent to him self so if you destroy him, and re-spawn him all his variables will reset, the game mode is persistent for the map, which means if you change map they default, and the game instance is persistent between run times, so they will not default until the game closes and restarts.

also did you set your settings here?

someone else had a similar problem. If you do not change this to your game mode, when you cast your game mode it’s failing, because that game mode doesn’t exist and the engine ran the default game mode

Did you ever figure this out?

Thanks shotty. That was what saved me. I do have a question though. The reason I was reading this page is that I wanted to use Restart Game node and I had ‘FirstPersonGameMode’ set as an override of the default GameMode (which is why I had trouble casting).

But my question is why can’t you connect ANY game mode reference to Restart Game node? Why does it have to be GameMode? Aren’t they all basically the same? Because from what I understand, it appears that you can only restart the game (by using Restart Game node), if you are using ‘GameMode’ game mode.

“Did you configure your project/level to use your MyGameMode instead of the default GameModeBase? Go to Edit > Project Settings > Maps & Modes and check the drop down for Map Mode.”

This solved my problem with my cast to game mode not working.

Thank you!!