I’ve been reading up on how to use Game Mode’s and now I’m wondering how i can set the variables of my custom game mode per map.
The game mode i made contains the game rules, win conditions etc. I want to re-use it for multiple maps, but i want some of the variables that it uses (time left to complete the level, amount of rockets the player can still use etc.) to be different per map. What would be the best approach to be able to do this?
There are several ways you could do this. What I would probably do, is create a base game mode, and then create children of that game mode for each individual map. That way, you could have a single game mode with all your logic, and override the inherited variables inside the children classes.
Alternatively, you could use the level blueprints to manually override the game mode’s values when the game begins play. The reason I don’t like doing that, is that it’s potentially more confusing to have code in every map modifying the game mode. It’s really whatever you find best for your game though.
I actually sorta have your second suggestion as of now. But I’m using a simple actor blueprint instead of the level blueprint. Since i had some problem using that as well.
The reason i don’t use your first suggestion is because i find it weird to create a separate game mode for each level. Where the logic is exactly the same but i only changed a few parameters. To me that feels as if for example instead of instantiating and placing actors in a level, you constantly recreate that actor blueprint but set the default position to be someplace else.
Creating a child blueprint is like creating a material instance. It’s part of the beauty of object oriented programming. With child blueprints, you get all of the variables and code of the original, and can override their initial values. This is valuable, because it’s much easier to keep track of. If you have a ‘level one’, and a ‘level one game mode’, you know that the two go together. If you’re overriding the values of the game mode from within the level, it can get confusing, because you’re setting the value of variables from multiple places, when they should remain static throughout gameplay.
Also, creating children is more expandable, because you can later add on extra code for each game mode if you so desire.
Ultimately, it’s up to you what you think is best. I’ve included a link with a bit of info on blueprint inheritance. Even if it’s not what you want here, it might help you later. Best of luck!
Wow, thank you for such a elaborate awnser! Knowing that this community has such helpfull people really makes the transition from unity a lot easier!
I like that you said that it would be like creating an instance. To me placing it in the world would be like creating an instance. And creating a child Blueprint would be like creating a subclass. I’ll look more into it!
Thanks a lot!
It seems the first solution cannot work for UObject, aka. you cannot assign reference of an actor in a level to a variable in game mode. it is no problem to set int, float, bool… any body know is there a way to set reference variable in game mode?