# Custom GameState class does not tick

**URL:** <https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180>\
**Category:** C++\
**Tags:** tick, gamestate, unreal-engine, CPP, question\
**Created:** [July 29, 2023, 9:22pm UTC](https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180 "2023-07-29T21:22:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![NightmareGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightmaregames/32/711529_2.png) [@NightmareGames](https://forums.unrealengine.com/u/NightmareGames)\
**Post date:** [July 29, 2023, 9:22pm UTC](https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180/1 "2023-07-29T21:22:22Z")

</div>

I have a GameState class which inherits from AGameStateBase. The BeginPlay() method fires correctly, but no breakpoints or functionality are hit in the Tick() function.

```auto
#include "CustomGameState.h"

void ACustomGameState::BeginPlay()
{
	testInt += 1;
}

void ACustomGameState::Tick(float DeltaTime)
{
	testInt += 1;
}

```

The test integer starts at 0 and goes to 1, but never gets higher than that.

I’m setting the GameState in the GameMode’s constructor like so:  
`	GameStateClass = ACustomGameState::StaticClass();`

The inheritance ladder looks like this:  
ACustomGameState : AGameStateBase : AInfo : AActor

The Tick function I’m overriding actually comes from AActor. Is there something extra I need to do either in the editor or in C++ to get that actor to start ticking?

---

<div class="post-metadata">

**Author:** ![ThePDub](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/thepdub/32/719651_2.png) [@ThePDub](https://forums.unrealengine.com/u/ThePDub)\
**Post date:** [July 29, 2023, 11:51pm UTC](https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180/2 "2023-07-29T23:51:39Z")

</div>

Hi friend!

Good question. Can you check that the field bCanEverTick is set to True?

---

<div class="post-metadata">

**Author:** ![ThePDub](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/thepdub/32/719651_2.png) [@ThePDub](https://forums.unrealengine.com/u/ThePDub)\
**Post date:** [July 29, 2023, 11:52pm UTC](https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180/3 "2023-07-29T23:52:05Z")

</div>

Also did some digging and this thread may contain some good info as well! [Custom GameMode And GameState Won't Tick [resolved] - #3 by Elou44](https://forums.unrealengine.com/t/custom-gamemode-and-gamestate-wont-tick-resolved/457352/3)

---

<div class="post-metadata">

**Author:** ![smelnick97](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@smelnick97](https://forums.unrealengine.com/u/smelnick97)\
**Post date:** [July 30, 2023, 4:49pm UTC](https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180/4 "2023-07-30T16:49:58Z")

</div>

Hey NightmareGames!

It looks like your BeginPlay function is missing a call to `Super::BeginPlay()`  
Like

```auto
void ACustomGameState::BeginPlay()
{
	Super::BeginPlay();
	testInt += 1;
}

```

Does it tick correctly if you add that in?

---

<div class="post-metadata">

**Author:** ![NightmareGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightmaregames/32/711529_2.png) [@NightmareGames](https://forums.unrealengine.com/u/NightmareGames)\
**Post date:** [August 5, 2023, 11:33pm UTC](https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180/5 "2023-08-05T23:33:21Z")

</div>

Thanks for the pointers. I can’t tell if bCanEverTick was true, but I’ve set it to true now. I’ve also added Super::BeginPlay, but there’s no change to the integer count.

Here’s my current game state:

```auto
void ACustomGameState::BeginPlay()
{
	Super::BeginPlay();

	PrimaryActorTick.bStartWithTickEnabled = true;
	PrimaryActorTick.bCanEverTick = true;

	testInt += 1;
}

void ACustomGameState::Tick(float DeltaTime)
{
	testInt += 1;
}

```

---

<div class="post-metadata">

**Author:** ![KaidoomDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaidoomdev/32/977996_2.png) [@KaidoomDev](https://forums.unrealengine.com/u/KaidoomDev)\
**Post date:** [August 6, 2023, 2:18am UTC](https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180/6 "2023-08-06T02:18:51Z")

</div>

Not sure if it matters but put these in constructor instead

```auto
PrimaryActorTick.bStartWithTickEnabled = true;
PrimaryActorTick.bCanEverTick = true;

```

---

<div class="post-metadata">

**Author:** ![NightmareGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightmaregames/32/711529_2.png) [@NightmareGames](https://forums.unrealengine.com/u/NightmareGames)\
**Post date:** [August 7, 2023, 12:40am UTC](https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180/7 "2023-08-07T00:40:30Z")

</div>

Okay. This is my new game state class. Still not ticking, unfortunately.

```auto
ACustomGameState::ACustomGameState()
{
	PrimaryActorTick.bStartWithTickEnabled = true;
	PrimaryActorTick.bCanEverTick = true;

	testInt += 1;
}

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

	testInt += 1;
}

void ACustomGameState::Tick(float DeltaTime)
{
	testInt += 1;
}

```

---

<div class="post-metadata">

**Author:** ![NightmareGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightmaregames/32/711529_2.png) [@NightmareGames](https://forums.unrealengine.com/u/NightmareGames)\
**Post date:** [August 7, 2023, 11:23pm UTC](https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180/8 "2023-08-07T23:23:58Z")

</div>

I took another look at my game mode (which I’m not using for anything yet) and noticed it’s still only the constructor.

As a wild hunch, I added a BeginPlay method to see what would happen.

```auto
void ACustomGameMode::BeginPlay()
{
}

```

Even though it contains no code, adding that caused the game state to start ticking. I don’t have a good explanation for that, aside from a vague knowledge that those two classes are closely related.

Even weirder is that after removing `ACustomGameMode::BeginPlay()`, the GameState still ticks. I especially can’t explain that one.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [September 6, 2023, 11:24pm UTC](https://forums.unrealengine.com/t/custom-gamestate-class-does-not-tick/1244180/9 "2023-09-06T23:24:24Z")

</div>

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