Some General Questions

Question 1. In the Simple Shooter section, the instructor created a GameMode after that derived a c++ class from it and wrote almost every code in the derived c++ class. I am wondering wasn’t it is easier to simply write code in the base class and not derive any other class out of it?

Base GameMode.h:-

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

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

/**
 * 
 */
UCLASS()
class SIMPLESHOOTER_API ASimpleShooterGameModeBase : public AGameModeBase
{
	GENERATED_BODY()

public:
	virtual void PawnKilled(APawn* DeadPawn);
};

Base GameMode.CPP:-

#include "SimpleShooterGameModeBase.h"

void ASimpleShooterGameModeBase::PawnKilled(APawn* DeadPawn)
{

}

Derived GameMode.h:-

#pragma once

#include "CoreMinimal.h"
#include "SimpleShooterGameModeBase.h"
#include "KillEmAllGameMode.generated.h"

/**
 * 
 */
UCLASS()
class SIMPLESHOOTER_API AKillEmAllGameMode : public ASimpleShooterGameModeBase
{
	GENERATED_BODY()

public:
	void PawnKilled(APawn* DeadPawn) override;
};

Derived GameMode.CPP:-

#include "KillEmAllGameMode.h"
#include "Character_PlayerController.h"

void AKillEmAllGameMode::PawnKilled(APawn* DeadPawn) //this function is used when the pawn which we are handling gets died
{
    ACharacter_PlayerController* PlayerController = Cast<ACharacter_PlayerController>(DeadPawn->GetController()); //assigning the pointer of the pawn controller

    if(PlayerController)
    {
        PlayerController->GameHasEnded(nullptr, false); //calling GameHasEnded Function because the pawn died
    }
}

Question 2. At the start of the simple shooter section, the instructor created a pawn class and also a blueprint out of it, but I am almost at the end of the section and till now the pawn class has been just a useless thing. So why did the instructor create it at the start?

Question 3. In the simple shooter section, the instructor used characters instead of pawns. What is the reason behind that? In the toon tank section, we were able to make a good game consisting of enemies using only pawns.

Question 4. When should we use **UWorld::GetAuthGameMode()** instead of **GetGameMode()** ?

Question 4. When should we use **AActor::GetInstigatorController()** instead of other functions to get controller?

  1. That was done so that you can have a common base class and have different game modes that do different things when a pawn dies. This code works with any game mode that derives from that. Say you want a time attack where you get more points based on how fast each kill was. That code shouldn’t change.
  2. That was just for demonstration. You can remove it.
  3. Because characters have a lot of stuff built in like movement and it all works in multiplayer too. Characters are for bipedal humanoid characters.
  4. The difference matters in multiplayer. GetAuthGameMode() will is always return a valid during gameplay on the server. Though for single player, it has the benefit of having a templated version which means you can write
    GetWorld()->GetAuthGameMode<AYourGameMode>()
    
    instead of
    Cast<AYourGameMode>(UGameplayStatics::GetGameMode(this))
    
  5. The instigator controller is the controller for the instigator for an actor. The instigator being the pawn responsible for a spawned actor doing damage. For example when you fire a projectile you could have the gun that fired it to be the owner of it, but the instigator would be the pawn that caused the gun to fire. It would be null if you don’t set it.
1 Like

I have one more question releated to Question No.1

For simple shooter project is it ok to make just base class of GameMode and write all code in the base class, instead of making a child GameMode Class.

@DanM

Sorry I missed your reply.

If you have no plans for other game modes, sure.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms