x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do you cast to the gamemode

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

alt text

Product Version: Not Selected
Tags:
more ▼

asked Jan 19 '17 at 10:24 PM in Blueprint Scripting

avatar image

Artboom91
1 3 5 6

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Jan 19 '17 at 10:29 PM

avatar image

elitereloaded
644 20 18 53

avatar image Artboom91 Jan 19 '17 at 11:32 PM

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

avatar image elitereloaded Jan 19 '17 at 11:42 PM

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.

avatar image yuyake79 Dec 12 '18 at 11:02 AM

"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!!

avatar image shotty46290 Jan 20 '17 at 12:46 AM

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.

avatar image elitereloaded Jan 26 '17 at 03:40 AM

Did you ever figure this out?

(comments are locked)
10|2000 characters needed characters left

also did you set your settings here?

alt text

alt text

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

71.jpg (127.5 kB)
72.jpg (239.4 kB)
more ▼

answered Jan 20 '17 at 02:56 AM

avatar image

shotty46290
348 11 7 19

avatar image mitjaprelovsek Dec 08 '17 at 12:33 PM

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.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question