GEngine is undefined in plug-in IInputDeviceModule::CreateInputDevice implementation

I’m building a plugin that during the runtime of a game, the plugin will create a socket to a service running on localhost.

Essentially, I’m trying to build a check into the plugin so that if the when the plugin is being executed in the editor, it will not attempt to create this socket.

I’m trying to do this by checking WorldType in my CreateInputDevice implementation.

This is the relevant block of code:

TSharedPtr< class IInputDevice > MyPluginImpl::CreateInputDevice(const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler)
{

	if (FModuleManager::Get().IsModuleLoaded("MyPlugin"))
	{
		UE_LOG(LogPureWeb, Warning, TEXT("Plugin Started"));
	}

	m_input = new CreateInputDevice(InMessageHandler);
	auto input = MakeShareable(m_input);
	
	if ((GEngine) && (GEngine->GetWorld()->WorldType == EWorldType::Game)){
		//Create socket
}
}

The problem is that when it hits the GEngine check, it fails on GEngine->GetWorld(), because it says GEngine is undefined.

I have included Engine.h, and I use GEngine elsewhere in the plugin, but it appears to not be available in this method.

I am clearly not going about this correctly, so any advice would be appreciated.

Thanks

I assume you mean it fails because GEngine is null? If the debugger says it is undefined, it simply means it does not have debug symbols for it, but that is not the cause of a crash.
Anyway, if all you want is for stuff not to happen in the editor, have you tried:

#if !WITH_EDITOR
// Stuff you do not want in the editor
#endif

This will be more efficient as code that should not be run will not even be compiled in the editor.

Well, that’s not what I was expecting, but it certainly fixes my problem. Thanks!