Where do you write code in for game level logic?

Where do I start writing game level logic at? In the Game Mode source code file? Or in a new Actor class code?

By game level logic, I mean a simple game with rules, winning and losing conditions, and score.

You could say that this is more about level creation than C++ code, but I am actually inclined towards how to start off by writing code for level creation.

So far, I only know how to write codes for actors and components, but I have no clue on where to start writing code for the game itself. When thinking about this, I also realized I am not used to writing games in component-oriented design. Unreal Engine 4 seemed to be component-oriented designing for game levels.

Since allot of games have different rules depending on which level you loaded, I normally store that kind of stuff in the Game Mode.

As an example, imagine you had a tutorial boss, and when your player died you wanted them to immediately restart in front of the boss again, no death sequence. For the rest of the game, you want a death sequence to kick off. In this case, you COULD put a check or make another actor for this ONE level, or you could make a custom game mode that inherits off the base and then has an override. This is only one approach, and with Unreal, you have many doors.

Are there any cases in which writing game level codes in the GameMode actor is not viable, feasible, or not recommended?

It heavily depends on what type of game you are making, and what unique problems you are running into.

Do you know what a game rule looks like in code? A sample code is fine.

I am asking this, is because I am writing conditional checking functions in my derived GameMode class, and without any references or something to compare, I don’t know if I am making a game rule the right way or not. I put in a lot of conditional checks, such as if a pawn can see the player, if a player is within range of pawn, if a pawn can hide behind an obstacle, if a pawn can hide and not get seen by player, and so on. If those aren’t game rules, then what is a game rule?

If it’s something like, if player gets 100 points, the game is over, then I can just create a conditional check that checks to see if player has accumulated 100 points, and if yes, end the game by calling this code in the Player class instead of GameMode:

if (Player.Points >= 100){

And that wouldn’t make a good game rule if it’s placed in the GameMode class… Hm… :confused:

Gameplay Classes in Documenation
Terminology For Classes
Gameplay Framework

Some good reading there for how to start and typically what goes where.

GameMode defines the rules of the ‘Game’ you’re playing. So, it determines how a player wins based on score, or where the objectives are etc.

Actor-based functionality goes into the Actor itself. If a Pawn needs to know if it’s in range of another, that goes there, not in the GameMode. If you want to set the range on a map-by-map basis or something, you could ask it to read a variable from the GameMode. Say for example in “Team Deathmatch” games you want a range of 1,000 and in “Free-For-All” games you want a range of 2,000 - you’d expose it to the GameMode and read from there. The Pawn itself would most likely want to handle the functionality.

The best advice I can give is that providing you’re comfortable with C++, download the ShooterGame sample and browse through it’s codebase. It’ll quickly give you an idea of what goes where and why, Unreal has an underlying architecture that you’ll want to stick to. GameMode classes for example, only exist on the Server in Multiplayer games.

Ah I see. Thanks for the clarification as well as something I can poke around in.