So I have this item pickup blueprint which has been perfectly fine up to this point, but needs a overhaul for setting up things I’m going to add at some point in the future.
You see, right now the variables for health & item pickups are currently housed within my current player character’s blueprint. This is a problem because I intend to have multiple playable characters in the game I’m working on and want all the characters to share the same health meter and item pickups. In order to facilitate this, my plan was to move the variables from my player character’s blueprint into the Game Mode blueprint and then modify the item pickups blueprints to use the new variables.
Unfortunately, the problem with this plan though is that trying to make these changes ends up resulting in my character being unable to pickup any items within the blueprints I’ve altered. I tried a couple of things including keeping the cast to the player character event and then adding a cast to the Game Mode event but to no avail.
Does anyone have any idea on how I can modify the above blueprint to allow it to utilize the variables with the Game Mode blueprint and not the ones within player character’s own blueprint, while still allowing my character to pickup items by coming into contact with them?
As always, any help whatsoever would be greatly appreciated!
I’m no blackbelt at this, but I’d say game mode is not the place. Game mode is there to tie all the various other BPs together ( HUD / first / third person / etc ).
Surely a better place would be game instance or save game?
I don’t understand what exactly is stopping you from using Get Game Mode → Cast to MyGameMode? It’s a framework class accessible from (almost) anywhere & anytime.
Also, I’d agree with the above, the Game Instance would be better here, especially if you have more than one level in the game.
just to complete - “accessible anywhere - at the SERVER”
The informations you want to save belong into the playerController or into the playerState. the information how much gems a pickup gives you, belongs into the pickupActor itself. If you do multiplayer and want to have a central place to track the stats on the server use the gameState for that. The gamemode should represent the “rules of the game”. So if you have some central rules - like “I need to capture the flag to get a point” - this rules and logic belongs into the gamemode. it is only available on the server - keep that in mind.
I’m not making a multiplayer game, the game I’m making is purely a single player experience. What I meant was the player would be able to switch between multiple different characters a la Donkey Kong 64 or Mystical Ninja Starring Goemon, hence the need for a health meter and coin pickups that are shared by everyone. After looking up what a Player Controller is, it looks like I need to create one of these and put the variables inside there along with basic movement inputs? Right now I only have one playable character that is of the Pawn/Character class.
hence the need for a health meter and
coin pickups that are shared by
As stated above, Get Game Mode → Cast to MyGameMode if you need to access variables stored there.
You could do the same with the Player Controller - but that’s blueprint more suited to handling input, especially when you have more than 1 playable character.
Blast it, my comment didn’t show up for some annoying reason. Anyways, Get Game Mode → Cast to MyGameMode worked like a charm so now my item pickups now work again. So I should store the variables for health & item pickups in the Game Mode ideally?
If you are ever going to have a single level only, it’s fine to handle global variables and saving in the Game Mode. Although you’ll hear that it is more reasonable to do it in the Game Instance as it persists throughout the game session.
To be perfectly honest, unless your game is exceptionally simple, I’d dedicate a separate actor to inventory management and handle all things related there. But then again, it depends on the scope of what you’re creating.
Yeah, nothing about the game I’m working on is simple so your probably right about moving the variables. I just moved the variables to the Game Mode and reworked my item pickup blueprints as well, so having to redo everything again is quite annoying, but its better to rejigger everything now while I’m still building the foundation of my game. Oh well, c’est la vie.