How does this header know about this class

So I have this code for a derived AIController which has a function that returns a derived Pawn class ATank and the code compiles fine yet if I’m not mistaken there’s no reference to ATank anywhere in this header, nor in any of the included headers (just the ones already included when you derive from AIController) and no forward declarations, surely this should get a compilation error?

#pragma once

#include "AIController.h"
#include "TankAIController.generated.h"


UCLASS()
class BATTLETANK_API ATankAIController : public AAIController
{
	GENERATED_BODY()

	virtual void BeginPlay() override;
	virtual void Tick(float DeltaSeconds) override;
		
	ATank* GetPlayerTank() const;
};

That happens sometimes, maybe because it is included in the generated header or the UCLASS macro adds them. Anyways you probably don’t have to worry about it. If you want to be safe you can import it manually or forward declare it and include in the source file if you need it.

So this gets into how the C++ build process works.

Somewhere down the build chain the ATank symbols are included before it gets to your ATankAIController header.

As a fun exercise, open up {ProjectDirectory}/Intermediate/Build/Win64/{ProjectName}Editor/Development/UnrealHeaderTool.manifest. This file is responsible for compiling all of your code, including the generated files.

You don’t technically need to add {{header}}.h to always use the defined symbols. Think about it from the engine point of view. You’re not constantly adding includes of each object you use, like for an FTimer, FName, TArray, etc… This stuff was defined (and processed) earlier.