# Retrieve GameMode and/or GameState in Editor

**URL:** <https://forums.unrealengine.com/t/retrieve-gamemode-and-or-gamestate-in-editor/401958>\
**Category:** Blueprint\
**Tags:** gamemode, gameinstance, unreal-engine, editor, CPP, Blueprint, question\
**Created:** [August 14, 2017, 6:14pm UTC](https://forums.unrealengine.com/t/retrieve-gamemode-and-or-gamestate-in-editor/401958 "2017-08-14T18:14:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7fcdb822](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7fcdb822](https://forums.unrealengine.com/u/anonymous_user_7fcdb822)\
**Post date:** [August 14, 2017, 6:14pm UTC](https://forums.unrealengine.com/t/retrieve-gamemode-and-or-gamestate-in-editor/401958/1 "2017-08-14T18:14:35Z")

</div>

I’m just trying to retrieve the Game Mode and Game State of the EditorWorld. For some reason it is always returning null.

I have made blueprint instances of my c++ classes for both the AGameModeBase and the AGameStateBase. Then in my Project Settings, I use those instances in maps and modes-\>Default Game Mode and maps and modes-\>Game State Class.  
Then in my UActorComponent, I try to get a handle on these instances like so:

```
auto EditorWorld = GEditor->GetEditorWorldContext().World();
if (EditorWorld) {
	auto GameState = EditorWorld->GetGameState();
	if (GameState) {
		BMoveSetupComponent = Cast<UBMoveSetupComponent>(GameState->GetComponentByClass(UBMoveSetupComponent::StaticClass()));
	}

	auto GameMode = EditorWorld->GetAuthGameMode();
	if (GameMode) {
		BMoveSetupComponent = Cast<UBMoveSetupComponent>(GameState->GetComponentByClass(UBMoveSetupComponent::StaticClass()));
	}

}

if (BMoveSetupComponent) {
	BMoveSetupComponent->TestFunction();
}

```

However GameState and GameMode are always NULL? I am not sure what to do?  
This is run while the editor is paused because I enabled the UActorComponent to tick while pause. I’d like to be able to retrieve either of these instances at any time. Is this possible?

---

<div class="post-metadata">

**Author:** ![Maghton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Maghton](https://forums.unrealengine.com/u/Maghton)\
**Post date:** [July 17, 2024, 9:25pm UTC](https://forums.unrealengine.com/t/retrieve-gamemode-and-or-gamestate-in-editor/401958/2 "2024-07-17T21:25:43Z")

</div>

hey I am facing the same problem right now. Did you manage to get the Game mode in the editor world?

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [July 17, 2024, 9:47pm UTC](https://forums.unrealengine.com/t/retrieve-gamemode-and-or-gamestate-in-editor/401958/3 "2024-07-17T21:47:00Z")

</div>

Have you tried accessing the world from the viewport?

```auto
UWorld* world = GEngine->GameViewport->GetWorld();

```

Not sure is gamemode is accessible before the game actually begins.
