#Include requirements query

In this lecture, we were told that we had to include both the Engine/World.h and GameFrameWork/PlayerController.h to be able to access the Player pawn from within the OpenDoor.cpp file.

However, I jumped the gun slightly and added the required code, successfully tested setting up the pawn and confirmed that I was able to open the doors in game before we were told to include these.

My includes are below:

#include "OpenDoor.h"
#include "GameFramework/Actor.h"

the relevent section of code is here:

ActorThatOpensDoor = GetWorld()->GetFirstPlayerController()->GetPawn();

I had no problems compiling and everything is working fine without the headers so I am slightly confused as to what is happening with this.

I am using Unreal 4.27.1 so I guess that may be why it works for me without the extra headers but after all the above information, I guess my questions are why does it work without these headers included and will not having them added now cause me issues further into the section?

Thanks in advance

Jamie

They would be included from other headers. It most likely worked without them back in 4.22 too. However you should still include them because

  1. It’s less fragile. Being dependant on a transitive include means that if any refactoring happens in the engine your code could break.
  2. IntelliSense sometimes doesn’t get the full include hierarchy sometimes as includes can be pulled in via means its doesn’t know about.
1 Like

Thank you very much for the clarification on this @DanM. Will go and include them now :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms