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”

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”

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

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

1 throws up an error.(2>C:\Users\Robert\Documents\Unreal Projects\MPPrototype\Source\MPPrototype\Playe - Pastebin.com) (.cpp #include "MPPrototype.h"#include "SlomoPlayerState.h"#include <CoreNet.h> - Pastebin.com)

2 Its not a good idea to include these two .h files into every single class since that will increase build times.

Getting Passive aggressive at me dosent help me ether. I didnt remove the PCH i literally just created the class. Ask ue4 why it deleted the file. Including the MyProject.h file after the class.h file changes nothing. It still tells me that it dosent know what component / ugameplaystatics is

Whoops forgot to “In the PCH header include Engine.h or EngineMinimal.h” that fixed it. Weird that ue4 dosent include these by default

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

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).