Im working on a board game → easy graphic work, better focus on pure code learning.
In my gamemode class I want to define different gamestyles as an enum (to be setted through blueprint widget menu), each of em will lead to a appropriate inferred subclasse of my super gamemode class. (maybe there is a better idea to have code cleaner on this ? Its just my idea for now) Depending on what gamestyle has been choosen, tokens are going to be placed differently, also differ in number and what algorithm will be used for the AI. My question ist, whats the proper way to setup such a gamemode, to have it spawning actors differently or even not? The board should be spawned everytime.-> so I guess the super gamemode is responsible for that to trigger? How can I keep the engine from just building everything if I hit play ? Or are the the board and token actors classes supposed to ask the gamemode class in their constructor how they should behave ? Im confused about the way objects are created in the engine since I do not access a regular main function here.
I think it will be better for you if you devide gamestyles between AGameModes. Made base AGameMode class which will have common aspects of all game modes and then make invidual game mode from that AGameMode class which will have invidual styles. You can make your base AGameMode to hold UClass* for diffrent classes related to specific mode like AI. As for card deplyment i’m not sure that card game you doing, designing that depends on rules you want to emply. Divide work between base class and invidual game mode class, i can give you good hint that might help you figure out how, “Don’t repeat yourself”, everything that is common and be repetitive in other AGameMode put in base class,
If you have no idea about inherence (base class and such), watch this and look on cat box example i’m using
But I would need to switch my gamemode class while the game already started, because its the final setting (choose your gamesytle) in the main that will be made before the level gets spawned. So I was told not to do that, because its not the way things are meant to be handled, rather to branch it in one gamemode class, whats your suggestion on that?
Sorry for late resoponce. If it’s late setting where the level is loaded, then yes it’s already too late to change game mode, you would need to restart the level with diffrent GameMode. In that case you could create a base class AGameStyle (derived from AInfo same as AGameMode) which would control the game style and GameMode would spawn it and let partly or fully control the game, you creat vbase clas AGameStyle and from AGameStyle you code diffrent styles. There you would have infor about which AI class to use, it would set up cards insted of AGameMode and so on. in AGameMOde you sould spawn right AGameStyle and let it control, you can make AGameMode call commands and such. IF you design this kind of system, think that you createing a framework, look on how AGameMode and APlayerController are made and try to mimic that for AGameStyle.
So I think this is pretty much what is expressing. Please don’t mind me adding to it:
You could create a GameMode that has a GameBehavior component (that you make). Depending on the type of game being played it would instantiate the correct GameBehavior for the game type. Example: Chess. If you select that you want to play Chess then make a ChessGameBehavior that contains the rules specific to Chess. Do the same with CheckersGameBehavior, etc.
So that GameBehavior component is meant to be derived from UActorComponent right ? Thank you for your help, I’ll get this done.
Yes, UActorComponent. I personally don’t know if component is good idea as you not gonna reuse it anywhere beyond GameMode, i think normal object would do the job.
Thank you.
I wonder how this “GameMode would spawn it and let partly or fully control the game” would look like ? Simply spawn an object of my gamestyle class in the beginplay function of gamemode ? I guess there is a way to make it delegate somehow ?
Just spawn it where ever you like or need
Thank you!