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?