Why do i have to include every single class i want to use

Hi after porting a blueprint project to a c++ project i ran into some problems. For some reason ue4 dosent know what UGameplayStatics is or what components are. I have to include all of that by hand wich i didnt have todo before in other 4.16 c++ projects. I am also using visual assist and then i auto include the classes it dosent recognize the file path (Something that worked in other projects)

It sounds like you might be missing #include “Core.h” or “CoreMinimal.h” in your .h in your Source root directory.

The Core files have a big list of all the common includes so you don’t have to include everything manually. The .h file is your precompiled header file, which all files in your project should include by default.

So, if you pop the core include in your PCH header file then you shouldn’t encounter this issue any more.

^^ UPDATE: EngineMinimal.h - this is what you need - at least for UGameplayStatics.

Coreminimal is there but Core.h is not i gonna try that and report back

Right I’ve double checked, core doesn’t bring in any kismet files (where gameplay statics live) try #including EngineMinimal.h.

NB. I think this may have been changed since previous projects; I’m quite sure that Engine used to be there by default in the PCH, but it’s just CoreMinimal now.

Thereshouldn’t be any harm in using EngineMinimal.h - at worst it will slow down a full rebuild, but not incremental builds unless you change the PCH.

Nope that dosent work. “error C2027: use of undefined type ‘UCameraComponent’” thats the error i am getting.

Not all of the headers are brought in - you do have to do some manually. The following components are brought in with Engine.h:
“Components/LightComponentBase.h”
“Components/SkinnedMeshComponent.h”
“Components/PawnNoiseEmitterComponent.h”
“Components/ChildActorComponent.h”
“Components/DecalComponent.h”
“Components/ExponentialHeightFogComponent.h”
“Components/DirectionalLightComponent.h”
“Components/SkyLightComponent.h”
“Components/PostProcessComponent.h”
“Components/ArrowComponent.h”
“Components/BillboardComponent.h”
“Components/BrushComponent.h”
“Components/DrawFrustumComponent.h”
“Components/LineBatchComponent.h”
“Components/MaterialBillboardComponent.h”
“Components/DestructibleComponent.h”
“Components/StaticMeshComponent.h”
“Components/InstancedStaticMeshComponent.h”
“Components/ModelComponent.h”
“Components/ShapeComponent.h”
“Components/DrawSphereComponent.h”
“Components/TextRenderComponent.h”
“Components/VectorFieldComponent.h”
“Components/ReflectionCaptureComponent.h”
“Components/BoxReflectionCaptureComponent.h”
“Components/PlaneReflectionCaptureComponent.h”
“Components/SphereReflectionCaptureComponent.h”
“Components/SceneCaptureComponent.h”
“Components/SceneCaptureComponent2D.h”
“Components/SceneCaptureComponentCube.h”
“Components/TimelineComponent.h”

When you updated, did you re-generate your visual studio files by right clicking the .uproject?

It should have sorted your gameplay statics though right?

There’s always some ehaders you have to bring in manually.

yes i deleted intermediate and regenerated my vs files

nope i still have to include it manually. Otherwise this happends: “‘UGameplayStatics’: is not a class or namespace name”

Thats why you include what you need and the reasson why is also stated there aswell as how you go back to the old way of doing it. IWYU is the Standard since 4.15 or 4.16 not sure. I recommand addating to it for the benefits of Compile times etc.

https://docs.unrealengine.com/latest/INT/Programming/UnrealBuildSystem/IWYUReferenceGuide/

Note: reverting to the old style does not mean you never have to include anything again :stuck_out_tongue_winking_eye:

Totally fair point there. We IWYU on our project. However FWIW it doesn’t make any difference to incremental compile times (unless the PCH is changed).

Right in that case, something’s seriously messed up with your project. I can tell you for a fact that EngineMinimal.h includes Kismet/GameplayStatics.h.

In your project can you verify that:

  • The file that throws up the gameplay statics error is referencing .h
  • has a #include for “Engine.h” or “EngineMinimal.h”
  • You don’t have any other errors (like missing include - sorry but I’ve got to ask)

Additionally, do you want to double click UGameplayStatics to hilight, then press Ctrl+F12? Just to check it’s actually taking you to the definition. Just to check your include directories aren’t messed up and the engine is definitely there.

Nope it dosent take me to the file.

But the other statements are true?

I dont have anything other that could throw up errors. I just made a blank c++ project and the same error persists. So that means that my engine version might be broken. I gonna try to reinstall 4.16 and see if it works then

Since you have a pretty new Project I guess you don´t mind Uploading the Code you have atm? www.pastebin.com .h .cpp please.

Playerstate.cpp #include "CapsPlayerState.h"#include <UnrealNetwork.h>#include <CoreNet.h> - Pastebin.com
PlayerState.h #pragma once#include "CoreMinimal.h"#include "GameFramework/PlayerState. - Pastebin.com
And thats the error that it throws up. 1>------ Build started: Project: UE4, Configuration: BuiltWithUnrealBuildTool Wi - Pastebin.com
When i manually include the gameplaystatics then this wont show up. But i didnt need todo that before

Dude - as stated, you need to include the precompiled header file. You need to put #include projectname.h at the top of the cpp. Additionally it’s Engine not core you need if you want a single, monolithic header file that brings in GameplayStatics.

Maybe I’ve misread your code, but as far as I can see you haven’t incorporated these changes as advised.

  1. Put the PCH include at the top of the CPP
  2. In the PCH header include Engine.h or EngineMinimal.h