What #include in the header and .cpp files?

What #include should I be placing in my header and .cpp files? I’m confused since my C++ aren’t recognizing some codes in the library. I’m running Version: 4.16.1-3466753+++UE4+Release-4.16 of Unreal.

I have the same question.

This is becoming a real problem now, as it seems that every challenge/mini challenge etc. kind of expects intellisense to work - but it doesn’t - so you give up and then try to follow the lecture hoping it will work when doing the build… which it doesn’t - and then leads to trying to figure out what #includes to use and whether to put them in the .h or .cpp…

I don’t understand how to find them, where to put them, and its starting to get so every lecture involves asking the same questions - all around includes…

The key point though, is that I don’t think I’m learning. The main way to learn is to try to do the challenges, to think for yourself - but its just not possible. The issues just make me more confused as opposed to enlightened.

3 Likes

Adding

#include “Engine.h”

to Grabber.h seems to help - but I’ve no idea if its the ideal solution or not…

I agree. they should have made this clear early on. hope they clear this up. please let me know if you finally know the answers. thanks.

I seem to be having the same issue, when typing in GetWorld, visual studios doesn’t recognize that. There are some other key terms that aren’t recognized as well, in the unreal documentation it will tell you what header files to use but when I add them in then I get a lot of errors where the namespace for the classes gets messed up.

Also if you get the namespace error like you have, what I do is I build it, save it, then close it out and reopen it.

#include “CoreMinimal.h”
#include “Components/ActorComponent.h”
#include “PositionReporter.generated.h”

this Is what I have in my Grabber.cpp file…

and for my header file it’s:

#include “Engine/World.h”
#include “CoreMinimal.h”
#include “Components/ActorComponent.h”
#include “Grabber.generated.h”

hope this helps =)

don’t forget to put:

#include “DrawDebugHelpers.h”

for your DrawDebugLine to work in the cpp file.

Hi I know it’s been a while since you wrote this comment, but I’d like to know if you found better ways to prevent this from happening as I also keep running into these problems and can’t use the intellisense… It’'s frustrating.

Also I added all these other header files that should help and tried different orders but the problem just gets worse.
My problem is mainly with GetWorld and GetOwner.

Hi Chris.

Not really. I just kept using Engine.h, and after a full rebuild then close/reopen of everything, it seemed to be working ok.

It just feels like in doing so, I’m going back on the changes to the Unreal Engine which introduced this change in the first place.

So, i was having the same issues y’all are having. I tried what the instructors advised, by adding the #includes in the pages, as the lesson progressed. However, after days and days of trying to figure it out, i finally stumbled onto it. I am using 4.16.3.

Below are all of my #includes for each tab. (note: my game is completed, and working)
Grabber.h -

Grabber.cpp -

OpenDoor.h -

OpenDoor.cpp -

PositionReporter.h -

PositionReporter.cpp -

Hi, thank you for making those screens, it gave me hope again as my project is totally wrecked.
I changed all my headers to your headers, and the problem only got even worse. :frowning:
I get more errors it does not understand what CLASS or even #include means anymore its CRAZY!
I feel very ****** as I put allot of effort into building a cool level with allot of detail, and I don’t feel exited to finish this course anymore. I have spend 40% of the time doing this course fixing Visual Studio problems. Unreal has not failed on me ever… its always VS…

I am going to restart the whole chapter AGAIN but then in his version of UE hoping the headers don’t need to change. If that does not work I will quit and learn only blueprints. Because I am no coding geek and I get crazy of fixing code 8 hours a day for nothing… then just making it worse. - end of rand.

I understand the frustration. I spent several days trying to figure out how to make mine work. Took a solid two weeks off from the course because I felt much like you do now. Finally though, I got my motivation back and also decided to start completely over on my Building Escape game. It was actually a good idea because i blew through the course much faster and with more understanding the second time. Honestly i think the whole course could use an update. At least at the point i’m at now, they’re using UE 4.11, and VS 2014 i think, while i was using 4.16.3 for Building Escape and VS 2017. I updated to 4.17 for Battle Tank. Anyways, don’t give up man! There’s a solution to your problem, and someone knows how to fix it, so keep trying, and asking questions!

Also, if you can, put up some screenshots of your headers.

Hi Eric,

Thank you very much for you encouraging comment. I rewatched 2 times and could not find all solutions. But I kept on going. Finally after enough debugging I got it compiling again. Just 2 more errors but it works!

Grabber.cpp is the only file causing issues now. (it compiles but we need Intellisense to work).

  • I reordered the Header files, and added “DrawDebugHelpers.h” to the list.
  • I temporary use “Engine.h” so I can work on while intellisense works, but I slows down compiling allot.
  • Other headers are clear of errors now. yay!
  • I’ve got 2x GetWorld() in the Grabber.ccp and I get them both to work after adding "Engine.h"
    Without including “Engine.h” only the second GetWorld works… weird right? Something in my code?
  • After using the Engine.h I get one error I don’t mind: identifier “FDrawingPoilicyRenderState” is undefinded". I do not use that in my code but I think some line points to that.

// Called every frame
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
	
	// Get player viewpoint this tick
	FVector PlayerViewPointLocation;
	FRotator PlayerViewPointRotation;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(   

/ ^^ This Getworld is wrong “pointer to incomplete class type is not allowed”

	OUT PlayerViewPointLocation,
	OUT PlayerViewPointRotation);

While below, in the same Grabber .cpp file, it does work. This is further down the code:

//draw a red trace in the world to visualize
DrawDebugLine(
	GetWorld(),
	PlayerViewPointLocation,
	LineTraceEnd,
	FColor(255, 0, 0),
	false,
	0.f,
	0.f,
	10.f
);

So when I use #include “Engine.h” is works fully. Seems like the code is not wrong it just wants another .h file to fix the first GetWorld()… But I have tried several to no succes. I rather fix this closer to the source than just adding engine.h to all of it.

The good news is at least I can move on for 10 mins. Heres hoping it does not come up again.

1 Like

You said it does compile though, correct? I’m pretty sure that those functions aren’t critical to the game itself, or the course. I only say that, because by the time the section is over, you will be taking that code out of your game. I remember having the exact same problem though. Here’s my entire Grabber.cpp, after having finished that section.
Feel free to use it to compare your code, but obviously, I wouldn’t suggest copying and pasting because that would defeat the purpose of the course. Glad you stuck with it!

Good luck!

1 Like

Don’t know if this helps, but have a look at the green-highlighted answer:
UCLASS error

It boils down to either:

  1. Having UCLASS on a different line than before; rebuilding the solution helps (UnrealHeaderTool needs to update the line number of UCLASS and GENERATED_BODY macros, Intellisense should then be able to figure it out)
  2. Having any include after “.generated.h” (don’t do that ! )

Updated Tue Sep 12 2017 22:43
You can test the 1. by simply adding an empty line before UCLASS, Intellisense will throw errors on mass, but it still compiles

Thanks man, yes I am also using 4.16.3 for Building Escape and VS 2017. It works now, and I will remove the engine.h when I’m done. I will keep your screens for when things go weird again. Thanks again!

Hi, I also had a lot of problems with the intellisense with red underlined errors appearing (false positives) that wouldn’t go away while the code was correct.
Now I just posted the solition I found in another thread on the forum, which worked for me. In short: Check the green highlighted answer on this page :slight_smile:

Hello! This might not be the best solution for a long term use, but what I did was just add all the needed Header files to my BuildingEscape.h file and when ever I’ve created a new CPP class I just do #include “BuildingEscape.h” which brings them all with. Also remember to always, in your newly generated classes, to have the #include “(classname).generated.h” as the last #include in your classes header file and the #include “(Classname).h” as the first #include in your CPP, otherwise the macro will go nuts. Hope that helps. Just going to do a copy paste what I have in my BuildingEscape.h file currently:

#include “CoreMinimal.h”
#include “Engine/World.h”
#include “GameFramework/Actor.h”
#include “GameFramework/PlayerController.h”
#include “Components/ActorComponent.h”
#include “Engine/TriggerVolume.h”

1 Like

Privacy & Terms