x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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)

Product Version: Not Selected
Tags:
more ▼

asked Jul 08 '17 at 06:23 PM in C++ Programming

avatar image

Gunschlinger
116 16 23 41

avatar image Katianie Jul 08 '17 at 08:28 PM

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

avatar image Gunschlinger Jul 08 '17 at 08:34 PM

yes i deleted intermediate and regenerated my vs files

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Jul 08 '17 at 06:27 PM

avatar image

DerPurpelHelmut
526 8 12 25

avatar image Gunschlinger Jul 08 '17 at 06:30 PM

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

avatar image DerPurpelHelmut Jul 08 '17 at 06:36 PM

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.

avatar image Gunschlinger Jul 08 '17 at 08:19 PM

Nope that dosent work. "error C2027: use of undefined type 'UCameraComponent'" thats the error i am getting.

avatar image DerPurpelHelmut Jul 08 '17 at 08:28 PM

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"

avatar image DerPurpelHelmut Jul 08 '17 at 08:30 PM

It should have sorted your gameplay statics though right?

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

avatar image Gunschlinger Jul 08 '17 at 08:35 PM

nope i still have to include it manually. Otherwise this happends: "'UGameplayStatics': is not a class or namespace name"

avatar image DerPurpelHelmut Jul 08 '17 at 08:48 PM

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.

avatar image Gunschlinger Jul 08 '17 at 08:51 PM

Nope it dosent take me to the file.

avatar image DerPurpelHelmut Jul 08 '17 at 08:53 PM

But the other statements are true?

avatar image Gunschlinger Jul 08 '17 at 08:56 PM

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

avatar image Nachtmahr Jul 08 '17 at 09:52 PM

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.

avatar image Gunschlinger Jul 09 '17 at 07:30 PM

Playerstate.cpp https://pastebin.com/bHqv5hLc PlayerState.h https://pastebin.com/HMSUivXh And thats the error that it throws up. https://pastebin.com/QUtNfxFq When i manually include the gameplaystatics then this wont show up. But i didnt need todo that before

avatar image DerPurpelHelmut Jul 09 '17 at 07:35 PM

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

avatar image Gunschlinger Jul 09 '17 at 07:48 PM

1 throws up an error.(https://pastebin.com/rRgQUdBZ) (.cpp https://pastebin.com/cigFNEA3)

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

avatar image DerPurpelHelmut Jul 09 '17 at 07:59 PM

Mate just go with me on this. If you need me to spell it out, I mean the first include after the header file, as the error tells you.

Where did you get this idea that it's not a good idea to include a PCH? Including a PCH decreases build times, sometimes by a factor of minutes. Regardless, think about concentrating on optimising compilation times after you have your build working. You should be including the PCH from every single definition file (and if you don't you will have to include things again and again.)

This the de facto way of working not only in UE4 but in any C++ project on a commercial team. It will also fix your problem!

avatar image Gunschlinger Jul 09 '17 at 08:03 PM

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

avatar image DerPurpelHelmut Jul 09 '17 at 08:12 PM

I'm terribly sorry if I've come across as aggressive Gunschlinger, that was not the intention at all; I'm simply trying to emphasise the point that you've been misinformed. You asked why you need to include every single file, the answer is technically you don't - include PCH, Engine.h in your PCH. Nachtmahr also offered an helpful alternative perspective on the challenge.

avatar image Gunschlinger Jul 09 '17 at 08:12 PM

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

avatar image DerPurpelHelmut Jul 09 '17 at 08:23 PM

Glad you got it working ;)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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/

more ▼

answered Jul 08 '17 at 08:42 PM

avatar image

Nachtmahr
7k 143 28 172

avatar image Nachtmahr Jul 08 '17 at 08:43 PM

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

avatar image DerPurpelHelmut Jul 08 '17 at 08:46 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question