How to call GameMode function from another Blueprint
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!
asked Feb 28 '16 at 09:49 PM in Blueprint Scripting
You can use the "Get Game Mode" node to get the current instance of the game mode. That should fix the problem for you.
answered Mar 01 '16 at 12:41 AM
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?
answered Feb 29 '16 at 06:16 PM
Excellent advice from you both! This not being an actual programming language makes me forget obvious things like initializing my variables. :P
answered Mar 06 '16 at 12:26 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here