Show map objects depending on game mode

Hi,

This is my first post here so sorry if I’m doing something wrong. :slight_smile:

I’m currently coding a Capture The Flag game mode in c++, using the ShooterGame as a base project.
I’d like to know what is the best way, without using blueprints if possible, to show / hide map objects on different maps depending on the game mode.
e.g I want CTF flag bases to be visible in CTF game mode but not in TDM, and so on.

Thanks

Thank you, will do!

I’ll answer here for anyone who wasn’t on the IRC channel when we discussed this :slight_smile:

Possibility 1:

For your CTF flags, say you have an AFlag object that you (or a map-maker) places in the world. Inside of this, you could check if it’s in a world where a CTF-type gamemode is active, and if not, the AFlag class will disable/destroy itself. For example:

If you have multiple gamemode classes, i.e. AGameMode → BaseShooterGameMode → CTFGameMode, you could just call GetWorld()->GetAuthGamemode(), and try to cast that to your CTFGameMode. If it fails, you run the above logic.

Possibility 2:

You could also have map-makers place an AFlagHolder or AFlagSpawn object, which is always present in the level, and which spawns an AFlag object when instructed. Using similar logic to the previous idea, you could enable/disable those spawns without having to delete anything. This would mean you wouldn’t have a flag appear at the start and then suddenly disappear when it realizes it’s not in the right gamemode.

This could be controlled either internally to the AFlagHolder/AFlagSpawn or in the CTFGameMode itself, which could find all flag-spawns via the GetAllActorsOfClass function. Additionally, if those spawners only executed when externally instructed, the non-CTF gamemodes would just never call AFlagSpawn->SpawnFlag(…), and thus having them appear is never an issue.

Let me know how you go!