What #include in the header and .cpp files?

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

If anyone is still struggling… In your header files, you should have the following includes:

#include "CoreMinimal.h"      // Must be first
(...)                         // Other #includes
#include "xxxxx.generated.h" // Must be last (xxxxx is the name of the header file itself)

In “other includes”, you should include the headers that define your base class and any other class that you use as member variables.

In your cpp files:

#include "xxxxx.h"      // Must be first (xxxxx is the name of the header file for this cpp file)
(...)                   // Other #includes

In “other includes”, you should include the headers that define any other class that you use in the code, and that have not already been included in your header (it’s ok to have the same include in both files).

After rearranging the #includes, try doing a full rebuild (ctrl+alt+F7) instead of a simple build (F7).

This issue is now wasting my time , where I’am fighting the editor and engine instead of learning…,

This whole “here’s a challenge” is also breaks train of thought.

Hey mate, where did you include the #include “DrawDebugHelpers.h”??
I’ve tried in various orders in the h and cpp file, but c++/visual comes up with errors

Might be a bit late now, but I just included it in Grabber.h file. :smiley:

If you are learning unreal and not trying to figure out C++ you are dealing with the unreal editor and new structure of it. intelisense follows that. If you are trying to figure out C++ while learning the game engine then yes it is confusing with the version changes. Don’t forget you can look at his code when you get lost. The code for this is updated per section.

Privacy & Terms