Compile Errors Didn't Go Away with "class AGun;"

In the course, he gets exactly the same errors as I am getting, and he forward declares class AGun and they just go away. In my case. They are still there.

ShooterCharacter.cpp:

#include "ShooterCharacter.h"
#include "Gun.h"

// Sets default values
AShooterCharacter::AShooterCharacter()
{
 	// Set this character 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 AShooterCharacter::BeginPlay()
{
	Super::BeginPlay();

	Gun = GetWorld()->SpawnActor<AGun>(GunClass);
	
}

ShooterCharacter.h:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "ShooterCharacter.generated.h"

class AGun;

UCLASS()
class SIMPLESHOOTER_API AShooterCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	AShooterCharacter();

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

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

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

private:

	void MoveForward(float AxisValue);
	void MoveSide(float AxisValue);
	void LookUpRate(float AxisValue);
	void LookRightRate(float AxisValue);

	UPROPERTY(EditAnywhere)
	float RotationRate = 100;

	UPROPERTY(EditDefaultsOnly)
	TSubclassOf<AGun> GunClass;

	UPROPERTY()
	AGun* Gun;

};

UE4 Errors:

Building SimpleShooterEditor...
Using Visual Studio 2019 14.24.28316 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314) and Windows 10.0.18362.0 SDK (C:\Program Files (x86)\Windows Kits\10).
Building 5 actions with 8 processes...
  [1/5] ShooterCharacter.gen.cpp
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter/ShooterCharacter.h(40) : error C2065: 'AGun': undeclared identifier
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter/ShooterCharacter.h(40) : error C2923: 'TSubclassOf': 'AGun' is not a valid template type argument for parameter 'TClass'
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter/ShooterCharacter.h(43) : error C2143: syntax error: missing ';' before '*'
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter/ShooterCharacter.h(43) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter/ShooterCharacter.h(43) : error C2238: unexpected token(s) preceding ';'
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter/ShooterCharacter.h(12) : error C2039: 'Gun': is not a member of 'AShooterCharacter'
  C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter/ShooterCharacter.h(10): note: see declaration of 'AShooterCharacter'
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter/ShooterCharacter.h(12) : error C2618: illegal member designator in offsetof
  C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter/ShooterCharacter.h(12): note: offsetof has a builtin meaning; use /Zc:offsetof- to revert to old, non-conforming definition
   C:\Users\Caleb\Documents\repos\SimpleShooter\Intermediate\Build\Win64\UE4Editor\Inc\SimpleShooter\ShooterCharacter.gen.cpp(68) : error C2039: 'Gun': is not a member of 'AShooterCharacter'
  C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter/ShooterCharacter.h(10): note: see declaration of 'AShooterCharacter'
   C:\Users\Caleb\Documents\repos\SimpleShooter\Intermediate\Build\Win64\UE4Editor\Inc\SimpleShooter\ShooterCharacter.gen.cpp(68) : error C2618: illegal member designator in offsetof
  C:\Users\Caleb\Documents\repos\SimpleShooter\Intermediate\Build\Win64\UE4Editor\Inc\SimpleShooter\ShooterCharacter.gen.cpp(68): note: offsetof has a builtin meaning; use /Zc:offsetof- to revert to old, non-conforming definition
   C:\Users\Caleb\Documents\repos\SimpleShooter\Intermediate\Build\Win64\UE4Editor\Inc\SimpleShooter\ShooterCharacter.gen.cpp(121) : error C2512: 'TSubclassOf': no appropriate default constructor available
  C:\Program Files\Epic Games\UE_4.25\Engine\Source\Runtime\CoreUObject\Public\Templates/SubclassOf.h(15): note: see declaration of 'TSubclassOf'
  [2/5] ShooterCharacter.cpp
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.h(40) : error C2065: 'AGun': undeclared identifier
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.h(40) : error C2923: 'TSubclassOf': 'AGun' is not a valid template type argument for parameter 'TClass'
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.h(43) : error C2143: syntax error: missing ';' before '*'
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.h(43) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.h(43) : error C2238: unexpected token(s) preceding ';'
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.h(12) : error C2039: 'Gun': is not a member of 'AShooterCharacter'
  C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.h(10): note: see declaration of 'AShooterCharacter'
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.h(12) : error C2618: illegal member designator in offsetof
  C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.h(12): note: offsetof has a builtin meaning; use /Zc:offsetof- to revert to old, non-conforming definition
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.cpp(9) : error C2512: 'TSubclassOf': no appropriate default constructor available
  C:\Program Files\Epic Games\UE_4.25\Engine\Source\Runtime\CoreUObject\Public\Templates/SubclassOf.h(15): note: see declaration of 'TSubclassOf'
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.cpp(20) : error C2065: 'Gun': undeclared identifier
   C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.cpp(20) : error C2664: 'T *UWorld::SpawnActor<AGun>(UClass *,const FActorSpawnParameters &)': cannot convert argument 1 from 'TSubclassOf' to 'const FActorSpawnParameters &'
          with
          [
              T=AGun
          ]
  C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.cpp(20): note: Reason: cannot convert from 'TSubclassOf' to 'const FActorSpawnParameters'
  C:\Users\Caleb\Documents\repos\SimpleShooter\Source\SimpleShooter\ShooterCharacter.cpp(20): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
  C:\Program Files\Epic Games\UE_4.25\Engine\Source\Runtime\Engine\Classes\Engine/World.h(3040): note: see declaration of 'UWorld::SpawnActor'

I have no idea why they aren’t going away. Any help would be appreciated. Thanks.

It turns out that ShooterCharacter.h wasn’t saved for whatever reason. No problems now.

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

Privacy & Terms