# How to check if game is running

**URL:** <https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567>\
**Category:** Plugins\
**Tags:** unreal-engine, editor, Plugins, UE4, question, CPP\
**Created:** [January 18, 2019, 3:01pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567 "2019-01-18T15:01:39Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herr\_Edgy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/herr_edgy/32/924115_2.png) [@Herr\_Edgy](https://forums.unrealengine.com/u/Herr_Edgy)\
**Post date:** [January 18, 2019, 3:01pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/1 "2019-01-18T15:01:39Z")

</div>

I’m creating an editor plugin, and depending on whether the game is running or not I need to get either pass either an object from a level (if the game is running), or use the editor world itself.

For that reason, I need the ability to know whether we are running the game or are still in the editor.

Preprocessor directives “#if WITH\_EDITOR” and the likes do not work because they tell about the build configuration, not whether we are actually in “edit-mode” or playing the game. Any advice?

---

<div class="post-metadata">

**Author:** ![AmphDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AmphDev](https://forums.unrealengine.com/u/AmphDev)\
**Post date:** [January 22, 2019, 12:28pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/2 "2019-01-22T12:28:30Z")

</div>

Hey,

Try to get current world type from UWorld if possible.

[https://api.unrealengine.com/INT/API/Runtime/Engine/Engine/UWorld/IsEditorWorld/index.html](https://api.unrealengine.com/INT/API/Runtime/Engine/Engine/UWorld/IsEditorWorld/index.html)  
[https://api.unrealengine.com/INT/API/Runtime/Engine/Engine/UWorld/IsGameWorld/index.html](https://api.unrealengine.com/INT/API/Runtime/Engine/Engine/UWorld/IsGameWorld/index.html)

Lot of other getter is there (like isPlayInEditor), check the doc

> **[UWorld](https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Engine/UWorld/)**
>
> The World is the top level object representing a map or a sandbox in which Actors and Components will exist and be rendered.

Cheers

---

<div class="post-metadata">

**Author:** ![Herr\_Edgy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/herr_edgy/32/924115_2.png) [@Herr\_Edgy](https://forums.unrealengine.com/u/Herr_Edgy)\
**Post date:** [January 22, 2019, 1:33pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/3 "2019-01-22T13:33:01Z")

</div>

Sadly I can not do that, because when in editor, trying to get the world of an object returns null.  
When the game is running, I want to access the object’s world.  
When it’s not running, I want to access the Editor World. I guess I could try and get the object’s world and if it returns nullptr I can just use the Editor World instead…

---

<div class="post-metadata">

**Author:** ![AmphDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AmphDev](https://forums.unrealengine.com/u/AmphDev)\
**Post date:** [January 22, 2019, 1:59pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/4 "2019-01-22T13:59:01Z")

</div>

GEditor-\>GetEditorWorldContext().World()  
should return editorworld i think

---

<div class="post-metadata">

**Author:** ![OverRated\_AU](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/overrated_au/32/1008648_2.png) [@OverRated\_AU](https://forums.unrealengine.com/u/OverRated_AU)\
**Post date:** [March 2, 2019, 6:35pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/5 "2019-03-02T18:35:10Z")

</div>

Just make your own node.

![270112-4346778b2f839f628bc8919291c4525f.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/a/d/7addeb826de640680a27b6c92b06099a8ed4e9ce.png)

---

<div class="post-metadata">

**Author:** ![goncasmage](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@goncasmage](https://forums.unrealengine.com/u/goncasmage)\
**Post date:** [March 12, 2019, 6:22pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/6 "2019-03-12T18:22:56Z")

</div>

What does that node do?

---

<div class="post-metadata">

**Author:** ![OverRated\_AU](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/overrated_au/32/1008648_2.png) [@OverRated\_AU](https://forums.unrealengine.com/u/OverRated_AU)\
**Post date:** [March 12, 2019, 10:27pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/7 "2019-03-12T22:27:04Z")

</div>

Just returns if the game is running in the editor it not.

---

<div class="post-metadata">

**Author:** ![SicoYu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SicoYu](https://forums.unrealengine.com/u/SicoYu)\
**Post date:** [September 17, 2020, 10:25pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/8 "2020-09-17T22:25:00Z")

</div>

no answer is right!

---

<div class="post-metadata">

**Author:** ![Herr\_Edgy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/herr_edgy/32/924115_2.png) [@Herr\_Edgy](https://forums.unrealengine.com/u/Herr_Edgy)\
**Post date:** [September 18, 2020, 11:03am UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/9 "2020-09-18T11:03:52Z")

</div>

Hey, you can access GEngine-\>GetWorldContexts, iterate over all the contexts and if at least one world is PIE you know at least one world is playing right now. That’s how I found it inside engine code a couple times.

---

<div class="post-metadata">

**Author:** ![Ledii](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ledii](https://forums.unrealengine.com/u/Ledii)\
**Post date:** [September 29, 2020, 1:58pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/10 "2020-09-29T13:58:22Z")

</div>

One way would be to check if the object returned from GetGameInstance is valid.  
It is created once the game starts, one way or another.

---

<div class="post-metadata">

**Author:** ![tuatec](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tuatec](https://forums.unrealengine.com/u/tuatec)\
**Post date:** [February 25, 2022, 9:44pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/12 "2022-02-25T21:44:58Z")

</div>

I know this thread is very old but the solution I found gives very precise results through the enumerator “EWorldType::Type” present in “Engine/EngineTypes.h” and you can easily extend it for PIE, Game, GamePreview …

Additionally, you can ask every UObject where it is currently running. 😉

```auto
// Utils.h
#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Utils.generated.h"

UCLASS()
class TTCOMMON_API UUtils : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
public:
	// returns true if the given 'Object' is instantiated and running in Editor Preview (e.g. Persona, AnimBP...)
	UFUNCTION(BlueprintCallable, Category = "Utils", meta = (Keywords = "editor tools"))
	static bool IsRunningInEditorPreview(UObject* Object);
};

// Utils.cpp
#include "UUtils.h"
#include "Engine/EngineTypes.h"
bool UUtils::IsRunningInEditorPreview(UObject* Object)
{
  if (!Object)
  {
    return false;
  }

  if (auto world = Object->GetWorld())
  {
    return world->WorldType == EWorldType::EditorPreview;
  }

  return false;
}

```

---

<div class="post-metadata">

**Author:** ![Cod3rChick](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cod3rchick/32/596803_2.png) [@Cod3rChick](https://forums.unrealengine.com/u/Cod3rChick)\
**Post date:** [October 23, 2022, 6:20am UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/13 "2022-10-23T06:20:14Z")

</div>

For those arriving here looking for a solution, I have one that works well for me. For context, I needed to keep a quit confirmation canvas panel off to the side during development, but got tired of having to move it. I wrote some code to automate that, but since UI/HUD elements are set up in the PreConstruct Event, this was running my code both during gameplay and while editing. To prevent that, I simply added a check to see if the Game Instance was valid and if not, don’t move the canvas into place. Works like a charm! Now the canvas only moves home to 0,0 when the game is actually being played. You could encapsulate the logic (Get Game Instance, CastTo GameInstanceName, IsValid) into a func that would allow this to be used as a single node, but it’s already small enough to use as is I think. Here’s what it looks like. Happy coding!!!

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/0/8/00817d2de14e3c3a9188ad67d36e39bf41cbbf02.png)

---

<div class="post-metadata">

**Author:** ![unrealredist](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@unrealredist](https://forums.unrealengine.com/u/unrealredist)\
**Post date:** [June 20, 2023, 3:30pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/14 "2023-06-20T15:30:12Z")

</div>

Thanks a lot ^^

---

<div class="post-metadata">

**Author:** ![Twads9816](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/twads9816/32/1049194_2.png) [@Twads9816](https://forums.unrealengine.com/u/Twads9816)\
**Post date:** [February 29, 2024, 2:52pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/15 "2024-02-29T14:52:06Z")

</div>

In my case all I needed to do was prevent execution from a Call In Editor event if the game isn’t running, so that my actor isn’t put into a bad state. A simple gate works perfectly, so I wanted to post this in case it’s useful to someone.  
 ![Gate using BeginPlay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/9/7d9b05020f0f829d36ec45c357f8fb135a8978a4.png)

---

<div class="post-metadata">

**Author:** ![syscrusher](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@syscrusher](https://forums.unrealengine.com/u/syscrusher)\
**Post date:** [March 5, 2024, 7:58am UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/16 "2024-03-05T07:58:45Z")

</div>

Good tip; thanks for sharing.

---

<div class="post-metadata">

**Author:** ![Evigmae](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/evigmae/32/1187349_2.png) [@Evigmae](https://forums.unrealengine.com/u/Evigmae)\
**Post date:** [July 6, 2024, 10:05pm UTC](https://forums.unrealengine.com/t/how-to-check-if-game-is-running/441567/17 "2024-07-06T22:05:20Z")

</div>

This is probably the intended way to go. I needed to check if something was in Editor, in Pie, or in Standlone.

So I made these 2 functions:

```auto
.h
// Returns true if this world is any kind of editor world (including editor preview worlds)
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
static bool CheckInEditor(UObject* WorldContextObject);

// Returns true if this world is any kind of game world (including PIE worlds)
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
static bool CheckInGame(UObject* WorldContextObject);

```

```auto
.cpp
bool UMyFunctionLibrary::CheckInEditor(UObject* WorldContextObject)
{
	return WorldContextObject->GetWorld()->IsEditorWorld();
}

bool UMyFunctionLibrary::CheckInGame(UObject* WorldContextObject)
{
	return WorldContextObject->GetWorld()->IsGameWorld();
}

```

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/d/3/1d3b0fbcdaf6b48f1a97bea7b609eb380bdb578e.png)

CheckInGame returns true if at Runtime, either in PIE or Standalone.  
CheckInEditor returns true if in the Editor or in PIE.

With these i can check the exact state of my game 🙂  
For example if I want to know if we’re in the Editor but not in PIE, CheckInGame must be false and CheckInEditor must be true.
