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.

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

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){
	this->GetWorld()->GetFirstPlayerController()->ConsoleCommand("quit");
}


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.