How to implement BeginPlay()/Tick() in a gamemode? [BEGINNER]

Hi! I am trying to get my gamemode do stuff when the game begins & every tick. Something I noticed that the default header file for GameMode does not include this, and just inserting “virtual void BeginPlay() override;” will not work. So… what does?

*Thanks in advance!

What you are doing should work fine. In my custom GameMode I have this:




//.h

UCLASS()
class SPACECOOP_API AGameModeCombat : public AGameMode
{
	GENERATED_BODY()
public:

        virtual void Tick(float DeltaSeconds) override;

	virtual void BeginPlay() override;
}


// .cpp


void AGameModeCombat::BeginPlay()
{
	Super::BeginPlay();

        // ...

}

void AGameModeCombat::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);
	
}


Works fine. If it’s not working for you - post any errors or your code, so we can help figure it out.

3 Likes

oh, well that explains. I did not know not implementing a function in .cpp too would lead to “unresolved external symbol”, I understood it as “there is no beginplay() to override”, and never thought adding the .cpp side of things would fix it.
I guess I learned something much more general and fundamental than I thought I would :stuck_out_tongue:

Thank you so much! :slight_smile:

EDIT: I successfully made the gamemode print “Hello World!” on BeginPlay(), and you can’t tell how happy it makes me :P. I finally “did a thing” in C++ :smiley:

2 Likes