[Youtube] Tanks game by Epic Games

Hi, I’m following Epic’s Tutorial of Tanks Game for C++. But there’s some issue with Compiling. I have exactly the same code as that of what instructors wrote but I can seem to get it compiled.

My Tank.cpp file:

// Fill out your copyright notice in the Description page of Project Settings.

#include "Tank.h"
#include "PaperSpriteComponent.h"

// Sets default values ATank::ATank() {  	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it. 	PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned void ATank::BeginPlay() { 	Super::BeginPlay(); 	 	if(!RootComponent) { 		RootComponent
= CreateDefaultSubobject<USceneComponent>(TEXT("TankBase")); 	}

	 	if (!RootComponent) 	{ 		RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("TankBase")); 	}

	TankDirection = CreateDefaultSubobject<UArrowComponent>(TEXT("TankDirection")); 	TankDirection->AttachTo(RootComponent);

	TankSprite = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("TankSprite")); 	TankSprite->AttachTo(TankDirection);

}

// Called every frame void ATank::Tick(float DeltaTime) { 	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

}

My Tank.h file:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Tank.generated.h"

UCLASS()
class TANKS_API ATank : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	ATank();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

private:
	// Helpful debug tool - which way is the tank facing?
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Tank", meta = (AllowPrivateAccess = "true"))
	class UArrowComponent* TankDirection;
	
	// Sprite for the tank body.
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Tank", meta = (AllowPrivateAccess = "true"))
	class UPaperSpriteComponent* TankSprite;
};

Errors:

       Running Mono...
        
        Setting up Mono
        /Users/Shared/Epic Games/UE_4.18/Engine /Users/Shared/Epic Games/UE_4.18/Engine/Binaries/Mac
        Compiling game modules for hot reload
        Performing 2 actions (8 in parallel)
        [1/2] Compile Tank.cpp
        /Users/ab

himanyuaryan/Documents/Unreal Projects/Tanks/Source/Tanks/Tank.cpp:30:15: error: member access into incomplete type 'class UArrowComponent'
            TankDirection->AttachTo(RootComponent);
                         ^
    ../../../../../abhimanyuaryan/Documents/Unreal Projects/Tanks/Source/Tanks/Tank.h:30:8: note: forward declaration of 'UArrowComponent'
            class UArrowComponent* TankDirection;
                  ^
    /Users/abhimanyuaryan/Documents/Unreal Projects/Tanks/Source/Tanks/Tank.cpp:33:14: warning: 'AttachTo' is deprecated: This function is deprecated, please use AttachToComponent instead. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile. [-Wdeprecated-declarations]
            TankSprite->AttachTo(TankDirection);
                        ^
    /Users/Shared/Epic Games/UE_4.18/Engine/Source/Runtime/Engine/Classes/Components/SceneComponent.h:641:7: note: 'AttachTo' has been explicitly marked deprecated here
            bool AttachTo(USceneComponent* InParent, FName InSocketName = NAME_None, EAttachLocation::Type AttachType = EAttachLocation::KeepRelativeOffset, bool bWeldSimulatedBodies = false);
                 ^
    /Users/abhimanyuaryan/Documents/Unreal Projects/Tanks/Source/Tanks/Tank.cpp:33:23: error: cannot initialize a parameter of type 'USceneComponent *' with an lvalue of type 'class UArrowComponent *'
            TankSprite->AttachTo(TankDirection);
                                 ^~~~~~~~~~~~~
    /Users/Shared/Epic Games/UE_4.18/Engine/Source/Runtime/Engine/Classes/Components/SceneComponent.h:641:33: note: passing argument to parameter 'InParent' here
            bool AttachTo(USceneComponent* InParent, FName InSocketName = NAME_None, EAttachLocation::Type AttachType = EAttachLocation::KeepRelativeOffset, bool bWeldSimulatedBodies = false);
                                           ^
    In file included from /Users/abhimanyuaryan/Documents/Unreal Projects/Tanks/Source/Tanks/Tank.cpp:1:
    In file included from /Users/Shared/Epic Games/UE_4.18/Engine/Intermediate/Build/Mac/UE4Editor/Development/Engine/SharedPCH.Engine.h:138:
    In file included from /Users/Shared/Epic Games/UE_4.18/Engine/Source/Runtime/Engine/Public/EngineSharedPCH.h:285:
    /Users/Shared/Epic Games/UE_4.18/Engine/Source/Runtime/CoreUObject/Public/UObject/Object.h:83:24: error: incomplete type 'UArrowComponent' named in nested name specifier
                    UClass* ReturnType = TReturnType::StaticClass();
                                         ^~~~~~~~~~~~~
    /Users/abhimanyuaryan/Documents/Unreal Projects/Tanks/Source/Tanks/Tank.cpp:29:18: note: in instantiation of function template specialization 'UObject::CreateDefaultSubobject<UArrowComponent>' requested here
            TankDirection = CreateDefaultSubobject<UArrowComponent>(TEXT("TankDirection"));
                            ^
    ../../../../../abhimanyuaryan/Documents/Unreal Projects/Tanks/Source/Tanks/Tank.h:30:8: note: forward declaration of 'UArrowComponent'
            class UArrowComponent* TankDirection;
                  ^
    In file included from /Users/abhimanyuaryan/Documents/Unreal Projects/Tanks/Source/Tanks/Tank.cpp:1:
    In file included from /Users/Shared/Epic Games/UE_4.18/Engine/Intermediate/Build/Mac/UE4Editor/Development/Engine/SharedPCH.Engine.h:138:
    In file included from /Users/Shared/Epic Games/UE_4.18/Engine/Source/Runtime/Engine/Public/EngineSharedPCH.h:285:
    /Users/Shared/Epic Games/UE_4.18/Engine/Source/Runtime/CoreUObject/Public/UObject/Object.h:83:35: error: incomplete definition of type 'UArrowComponent'
                    UClass* ReturnType = TReturnType::StaticClass();
                                         ~~~~~~~~~~~^~
    1 warning and 4 errors generated.
    ERROR: UBT ERROR: Failed to produce item: /Users/abhimanyuaryan/Documents/Unreal Projects/Tanks/Binaries/Mac/UE4Editor-Tanks-6461.dylib
    Total build time: 12.14 seconds (Local exec

utor: 0.00 seconds)

you need to include UArrowComponent.h into your source file.

They haven’t included UArrowComponent.h in their file either. How come it works? @Flash7

also I get an error now #include “UArrowComponent.h” file not found in Tank.cpp

There’s no inbuilt header file with UArrowComponent.h name. That is why we forward declared the class UArrowComponent.h in header file

ok it worked #include “Components/ArrowComponent.h”

Their example is an old example. Epic did a change I believe in 4.15 or so to the source code include files where they removed one large include file in exchange of including only what you need.

also, if it worked, can you please mark your question as solved?