praca_magisterska/games/unreal/tutorial/part-8-cpp-create-game-mode.md
Copilot dd009a0029
Add C++ code-first tutorial for Unreal bullet-hell game (#2)
* Initial plan

* Add C++ code-first tutorial approach for Unreal game

Co-authored-by: kuhyx <147418882+kuhyx@users.noreply.github.com>

* Add quick start guide for code-first approach

Co-authored-by: kuhyx <147418882+kuhyx@users.noreply.github.com>

* Restructure C++ tutorial into part-by-part format and add migration guide

Co-authored-by: kuhyx <147418882+kuhyx@users.noreply.github.com>

* Address PR feedback: improve part-1, add Expected Results, split parts 4-9 into separate files

Co-authored-by: kuhyx <147418882+kuhyx@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: kuhyx <147418882+kuhyx@users.noreply.github.com>
2026-01-08 16:44:56 +01:00

1.9 KiB

Part 8 (C++): Create Game Mode

← Previous: Part 7 (C++) - Create UI | Back to Index | Next: Part 9 (C++) - Final Setup →


Overview

Create a custom Game Mode to set the default pawn class and manage game rules.

Time: ~5 minutes


Step 8.1: Create STGGameMode C++ Class

  1. Tools → New C++ Class
  2. Choose "Game Mode Base" as parent
  3. Name: STGGameMode
  4. Create Class

Step 8.2: Define Game Mode

STGGameMode.h:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "STGGameMode.generated.h"

UCLASS()
class BULLETHELLGAME_API ASTGGameMode : public AGameModeBase
{
    GENERATED_BODY()
    
public:
    ASTGGameMode();
};

STGGameMode.cpp:

#include "STGGameMode.h"
#include "STGPawn.h"

ASTGGameMode::ASTGGameMode()
{
    // Set default pawn class to our player
    DefaultPawnClass = ASTGPawn::StaticClass();
    
    // Disable auto-possess (we'll handle spawning ourselves)
    bStartPlayersAsSpectators = false;
}

Step 8.3: Set Game Mode in Project Settings

  1. Edit → Project Settings
  2. Project → Maps & Modes
  3. Under "Default Modes":
    • Default GameMode → Select STGGameMode
  4. Close Project Settings

Step 8.4: Test

Create a new level or use existing one:

  1. File → New Level → Empty Level

  2. Save as BulletHellLevel

  3. Add:

    • Player Start (from Place Actors panel)
    • STGEnemySpawner
    • STGGameDirector
    • STGHUDManager
    • Directional Light (for visibility)
  4. Press Play

Expected Result:

  • Player automatically spawns at Player Start location
  • No need to manually drag BP_Player into level
  • All game systems work together

← Previous: Part 7 (C++) - Create UI | Back to Index | Next: Part 9 (C++) - Final Setup →