Download

[HELP]After Using My Own Gamemode file, no tick and begin play() event happen to my character

It’s a really simple code
And it works when I set the gamemode to the default, what it does is to move a block upward
However, when applied my own gamemode class, my pawn never move or update anymore…

my code below

FPTryGameMode.cpp


#include "FPTry.h"

#include "FPTryGameMode.h"

#include "Engine.h"

void AFPTryGameMode::StartPlay(){


Super::BeginPlay();


if (GEngine){

    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));

}


StartMatch();

}

FPTryGameMode.h


#pragma once




#include "GameFramework/GameMode.h"

#include "FPTryGameMode.generated.h"




/**

 * 

 */

UCLASS()

class FPTRY_API AFPTryGameMode : public AGameMode

{

    GENERATED_UCLASS_BODY()

    virtual void StartPlay() override;



};


MyPawn.cpp



#include "FPTry.h"

#include "MyPawn.h"

#include "Engine.h"







// Sets default values

AMyPawn::AMyPawn()

{

     // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.

    PrimaryActorTick.bCanEverTick = true;



    Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));

    RootComponent = Root; // Remember this RootComponent



    Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));

    Mesh->AttachToComponent(Root, FAttachmentTransformRules::SnapToTargetNotIncludingScale); // Not allow to transform as the parent transform






}




// Called when the game starts or when spawned

void AMyPawn::BeginPlay()

{

    Super::BeginPlay();



}




// Called every frame

void AMyPawn::Tick( float DeltaTime )

{

    Super::Tick( DeltaTime );

    FVector NewLocation;

    NewLocation = GetActorLocation();

    NewLocation.Z += 1.f;

    SetActorLocation(NewLocation);

    if (GEngine){

        GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("FPS Char"));

    }

}




// Called to bind functionality to input

void AMyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)

{

    Super::SetupPlayerInputComponent(InputComponent);




}


MyPawn.h


#pragma once




#include "Engine.h"

#include "GameFramework/Pawn.h"

#include "MyPawn.generated.h"







UCLASS()

class FPTRY_API AMyPawn : public APawn

{

    GENERATED_BODY()




public:

    // Sets default values for this pawn's properties

    AMyPawn();




    // Called when the game starts or when spawned

    virtual void BeginPlay() override;



    // Called every frame

    virtual void Tick( float DeltaSeconds ) override;




    // Called to bind functionality to input

    virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;




    UPROPERTY(EditAnyWhere)

    USceneComponent* Root;



    UPROPERTY(EditAnyWhere)

    UStaticMeshComponent* Mesh;





};

I don’t really know whether it’s a big mistake or just a little mess
but I’ve stuck by the problem for hours and I cannot figure out why?
Will be very thankful if anyone could help……

Your overloaded method for StartPlay is calling Super::BeginPlay, not Super::StartPlay, so that may be your issue.

It works, so really thanks.