Unreal Compiling errors

Dear Unreal Community

I am having issues compiling my C++ code. I want to compile my code and a piece that was previously fine is now giving syntax errors.



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

	UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
		USphereComponent* m_CollisionComponent;

	UPROPERTY(VisibleAnywhere, Category = Movement)
		UProjectileMovementComponent* m_ProjectileMovementComponent;

	void FireInDirection(const FVector& ShootDirection);


The error it gives is:

1>d:\documents - data\unreal projects\fpsproject\source\fpsproject\FPSProjectile.h(27): error C2143: syntax error: missing ‘;’ before ‘
1>d:\documents - data\unreal projects\fpsproject\source\fpsproject\FPSProjectile.h(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\documents - data\unreal projects\fpsproject\source\fpsproject\FPSProjectile.h(27): error C2238: unexpected token(s) preceding ‘;’
1>d:\documents - data\unreal projects\fpsproject\source\fpsproject\FPSProjectile.h(30): error C2143: syntax error: missing ‘;’ before '

1>d:\documents - data\unreal projects\fpsproject\source\fpsproject\FPSProjectile.h(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\documents - data\unreal projects\fpsproject\source\fpsproject\FPSProjectile.h(30): error C2238: unexpected token(s) preceding ‘;’
1>D:\Documents - Data\Unreal Projects\FPSProject\Source\FPSProject\FPSProjectile.cpp(12): error C2065: ‘m_CollisionComponent’: undeclared identifier
1>D:\Documents - Data\Unreal Projects\FPSProject\Source\FPSProject\FPSProjectile.cpp(12): error C2065: ‘USphereComponent’: undeclared identifier
1>D:\Documents - Data\Unreal Projects\FPSProject\Source\FPSProject\FPSProjectile.cpp(12): error C2672: ‘UObject::CreateDefaultSubobject’: no matching overloaded function found
1>D:\Documents - Data\Unreal Projects\FPSProject\Source\FPSProject\FPSProjectile.cpp(12): error C2974: ‘UObject::CreateDefaultSubobject’: invalid template argument for ‘TReturnType’, type expected
1> C:\UE4\UE_4.16\Engine\Source\Runtime\CoreUObject\Public\UObject/Object.h(95): note: see declaration of ‘UObject::CreateDefaultSubobject’
1>D:\Documents - Data\Unreal Projects\FPSProject\Source\FPSProject\FPSProjectile.cpp(14): error C2065: ‘m_CollisionComponent’: undeclared identifier
1>D:\Documents - Data\Unreal Projects\FPSProject\Source\FPSProject\FPSProjectile.cpp(14): error C2227: left of ‘->InitSphereRadius’ must point to class/struct/union/generic type

This happens frequently, sometimes I can fix it by retyping the code and compiling. I am following the FPS tutorial and I can just literally copy paste the code but it still gives me the same errors.
I did restart Unreal and my PC. Is this a known bug or should I reinstall UE4 and/or VS015?

Thanks in advance

You’re missing includes for those components. Add the following to the top of that file:



#include "Components/SphereComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"


Thank you for the help! That fixed it.