How to call GameMode function from another Blueprint

Hello,

I’m trying to call a function “Hide World” that lives on my game mode blueprint from my main player character. This function handles hiding objects in the world. I call the function from the character via a button press. It’s all pretty simple. However, the function on the game mode isn’t being hit (no breakpoint is hit), but the call on the character blueprint does hit the “Hide World” function and moves along to the next execution pin, without actually hitting the breakpoint inside “Hide World”.

I have created a variable for the game mode, of which I only have the one default one that came with the sample SideScrollerCharacter Unreal project. I created a new variable in the character blueprint and gave it a variable type of Side Scroller Game Mode from it’s dropdown and flagged it as editable via the tips on some of the other similar links.

As you can see, it already knows the specific target, and even yelled at me when I tried to cast it. Do I need a target instance instead and perhaps this is just hitting some default blueprint and that’s why it’s not working? On my game mode function breakpoint I have no filters on the breakpoint, so it should trigger on any blueprint call.

Any tips are greatly appreciated. Thanks!

80327-unreal_character.png

did you initialize the variable? so for example, in your character’s blueprint, on begin play, did you call ‘get game mode’ and cast the returned value to ‘yourCustomGameMode’ and then set the variable ‘GameMode’ (by the way, this naming might confuse you down the line. you may want to rename it to something more specific) to your objected returned from the cast?

You can use the “Get Game Mode” node to get the current instance of the game mode. That should fix the problem for you.

Excellent advice from you both! This not being an actual programming language makes me forget obvious things like initializing my variables. :stuck_out_tongue:

Glad I could help. Could you please mark the question as solved by the answer of choice? Thanks. =)

I tried and couldn’t find out what button it was. Thanks for following up, got it this time. :slight_smile:

Also to cast to the actually game mode class you’re using.