How to effeciently reference game mode?

Hi all.

I’m working on a rogue like style game that has lots of custom parameters and rules that the game mode holds (think stuff like enemy damage multipliers, changes to drop rates, etc).

What this means is that many actors in my game need to get a reference to the game mode and read it’s data, such as enemies, the player characters, chests, etc.

I’m currently using the “Get Game Mode” node, but it requires me to then cast to my specific game mode. I’m planning on just having my actors do this during initialization to save the game mode as a variable. But since I’ve got a lot of actors that do this, it seems like my current method is a bit clunky and expensive. I’d rather not have to cast on every single actor that needs to read from my game mode, especially when I’m spawning in enemies and things at runtime.

Just wondering if there’s a more elegant way to do this.

Thanks!

1 Like

Yup: blueprint interfaces :slight_smile:

Put a BP interface on your game mode, and you can directly make the call on the GetGameMode node.

Trouble is, then you need an interface call for each type of access, each caller with different requirements will need a function in the BPI to access the GM.

It’s totally possible, as I did in fact write my entire save game system in this way while I was trying to find a ‘asset reference leak’ in the game. Good decoupling too…

327576-screenshot-1.jpg

1 Like

Haha, ClockworkOcean beat me to it! (■■■■ Answerhub relogging in system :D)

Just to add further, if its a small project, I wouldn’t worry too much, however, if it’s a larger project then perhaps you might want to consider how and where your data is being stored.

The GameMode is supposed to contain the rules and properties for the active level and levels which use similar mechanics, therefore things that affect a specific pawn’s behavior might be best saved elsewhere.

I will give a quick breakdown of the major controller classes:

Game Instance = Rules for the application

Game Mode = See above

Game State = Facebook profile for the Game Mode (networking).

Player Controller = Rules for a specific input entity such as a human user or AI user

Player State = Facebook profile for the Player Controller (networking)

Pawn / Character = Display and navigation rules for a specific controller.

Level BP = Setup and manage relationships between objects in the world.

However, as ClocworkOcean mentioned, in this case interfaces are your friend.

Hope this helps.

Alex

1 Like

Awesome, this is exactly what I’m looking for. Cheers!