Error: identifier "GEngine" is undefined

Hi there,

i’m currently starting to work with UE4. I wanted to create some DebugMessages and i’ve seen these one in this format:

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::FString("PlaneRotation.Roll = ") + FString::SanitizeFloat(PlaneRotation.Roll));

If u click on the image, you see “GEngine” is underlined red and I get the following message: Error: identifier “GEngine” is undefined

This snippet is extracted from the Tick Function. I used the Flying-Project, from the Starter-Content and didn’t add much content.

How can i fix this?

Another question: Can I implement this debug message in a way, that i only see one line when testing(which also gets updated) and not 100 due to the “Tick-Function”?

Thanks for your help,
smara :slight_smile:

Are you sure it’s not an Intellisense issue? That Error is from hovering the red underline or from building output? If it’s the first case, try building it.

Error List after trying to build:

Solution: https://forums.unrealengine.com/showthread.php?30502-4-4-What-happened-to-EngineGlobals-h&highlight=gengine

Due to the update from 4.3.1 -> 4.4 GEngine is not public anymore(see Link)

1 Like

[FONT=Comic Sans MS]Solution

GEngine is still alive and well and still public.

The issue is actually really simple! (though it did have me confused for a good 20 minutes once I started a new 4.4 project)

New projects have this in their MyProject.h


#include "EngineMinimal.h"

Replace the above with this


#include "Engine.h"

and you will have GEngine back again :slight_smile:

Rama

6 Likes

Woo! You’re the best Rama. (First post)
In the beginning stages of my first oculus rift + UE4 game

Congrats on your first Post!

Welcome to the forums!

:slight_smile:

Rama

Lifesaver!

Save your compile time or go for a coffee!

Please don’t include the whole Engine if you don’t need it.

EngineMinimal.h gives you all you need. If something is in any file missing it is much better
to include it only there and not for the whole module.

So if you want to save compile time and want to have the missing GEngine please include following:


#include "Runtime/Engine/Public/EngineGlobals.h"

There is the GEngine declared being an extern variable – meaning: GEngine* is somewhere, global static, in the memory.

Hope that helps!

3 Likes

This didnt fix the error. Instead it threw an “UEngine undefined type” Error. According to internet posts this is fixed by including “Engine.h” instead of “EngineMinimal.h”. Is this really the only way?

UEngine is defined in “Engine/Engine.h”

I realize that is a bit confusing but it is a different file inside the classes folder rather than the public folder.

Also you should be able to use “EngineGlobals.h” instead of the full path.

Edit: First of all you need to understand what is happening here. I don’t think you do. The basic “Engine.h” merely includes a bunch of other files. Find the file on your disk at “Source\Runtime\Engine\Public\Engine.h” and open it to see what it is doing.

The point of the advice being given is to not include all of those other headers that you don’t actually need since it just inflates your compile time.

The error you receive means that you did not include the header file where UEngine was defined. You can find that in “Source\Runtime\Engine\Classes\Engine.h”.

With the way compilation works, you only need to specify part of the path in your source file. So this is what you would need:

include “EngineGlobals.h”
include “Engine/Engine.h”

Truth to be told, I really did not think about it yesterday myself :open_mouth: We need to include the class UEngine expliclity of course, since we (or me in this case) access a member of GEngine… Forward declarations are of course not enough in such a case.

Though I did not know about the shorter include paths, thank you very much :wink: Sorry about my thoughtlessness

include “Engine/Engine.h” will be the right way to include!

Has anyone successfully included GEngine in the most recent versions of Unreal (4.23 specifically)? I’ve tried the different combinations of #includes suggested above and nothing seems to be working.

if
#include “Engine/Engine.h”
or
#include “Engine.h”

does not work for you then there is something wrong with your installation.

Some nice header files were made specially for that and make importing the whole engine less necessary, this way you simply import what you need which makes everything run better in the end. The line that Dwarfmine suggested is one of them and should make GEngine work.


#include "Runtime/Engine/Public/EngineGlobals.h"

You could also replace with this line with the one below since everything in the public path should be available right away when you include:


#Include "EngineGlobals.h"

I only use AddOnScreenDebugMessage so far since I am following the fps C++ tutorial and fixing the errors I get as they come in, but it should still work.

If a declaration is missing something I would recommend is trying to find it in the documentation wiki. It is better to include only what you need to save compilation time rather than include the whole thing and possibly cause other problems along the way.
But then again, I am not using the UEngine declaration, I only needed GEngine.

Hopefully it helped ^^

2 Likes

What about Unreal 5.1? I am trying to do this, and everything mentioned here doesn’t work for me - GEditor is udefined.

2 Likes

Something not mentioned here, but I will add this for the future readers.

There are always two parts to the build system. Including the correct file via the include directive is the first step.

The second step is to also include the correct module that the include directive is referring to. This is done via your modules YourModule.build.cs file, just outside your modules source directory.

For Projects this is Source/ModuleName/*build.cs
For plugins it’s Plugins/PluginName/Source/ModuleName/*build.cs

There are two main distinctions for modules, which are defined either in a .uplugin or .uproject files Json. They can either be Runtime or Editor modules.

Runtime modules can reference all types of modules, while editor modules can only reference editor modules. Since you are looking for GEditor, this will be defined in an editor module, and so if you are linking against this inside a runtime module - you’ll need to do some extra work to ensure that the runtime module doesn’t try to reference things OUTSIDE the Editor.

Lets look at a build.cs file for a runtime module needed for referencing GEditor.

        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Slate", "SlateCore", "UMG", "DeveloperSettings", "Projects", });

        PrivateDependencyModuleNames.AddRange(new string[] { });

        if (Target.Type == TargetType.Editor)
        {
	        PrivateIncludePathModuleNames.AddRange(
		        new string[]
		        {
			        "Settings",
			        "UnrealEd",

				});
	        PublicIncludePathModuleNames.AddRange(
		        new string[]
		        {
			        "Settings",
			        "UnrealEd",
	
		        });
			PrivateDependencyModuleNames.AddRange(
		        new string[]
		        {
					"UnrealEd"
				}
	        );
	        PublicDependencyModuleNames.AddRange(
		        new string[]
		        {
			        "UnrealEd"
				});
        }

	}

IncludePathModuleNames are names of other modules that your .cpp (private) or .h (public) files are include directives are referencing. This makes it so that other modules that include YOUR module also get these paths available to them.

The DependencyModuleNames are the same idea, except this is to tell the linker that you are referencing types defined in those modules.

Notice how I’ve blocked my modules includes off to only happen when the runtime module is being build for the Editor and at no other time.

This means both your include directive and your code referencing GEditor directly need to be wrapped in the #if WITH_EDITOR macro so it also doesn’t get compiled outside the editor context, as those modules will not exist because they are Editor modules.

So to get the GEditor global var to work in a runtime module, you need to modify the build.cs to support it and do something like this

#if WITH_EDITOR
#include "Editor/EditorEngine.h"
#endif

static bool IsEditorEngine()
{
    #if WITH_EDITOR
      if(GEditor) return true;
    #endif
return false;
}
1 Like