I got issue when i want to create a box collision by UBoxComponent.
There is my code. Thanks for any help!
Weapon.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Weapon.generated.h"
UCLASS()
class FPSGAME_API AWeapon : public AActor
{
GENERATED_UCLASS_BODY()
void WeaponFire();
void WeaponReload();
UPROPERTY(VisibleDefaultsOnly, Category = Config)
UBoxComponent* CollisionComp;
UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
USkeletalMeshComponent* Mesh1P;
};
Weapon.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Weapon/Weapon.h"
// Sets default values
AWeapon::AWeapon(const FObjectInitializer& ObjectInitializer) :Super(ObjectInitializer)
{
CollisionComp = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("CollisionComp"));
RootComponent = CollisionComp;
Mesh1P = ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("Mesh1P"));
Mesh1P->SetupAttachment(CollisionComp);
}
void AWeapon::WeaponFire()
{
}
void AWeapon::WeaponReload()
{
}
Error:
1>D:\Program Files\Epic Games\Unreal Project\FPSGame\Source\FPSGame\Public\Weapon/Weapon.h(18): error C2143: syntax error: missing ';' before '*'
1>D:\Program Files\Epic Games\Unreal Project\FPSGame\Source\FPSGame\Public\Weapon/Weapon.h(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Program Files\Epic Games\Unreal Project\FPSGame\Source\FPSGame\Public\Weapon/Weapon.h(18): error C2238: unexpected token(s) preceding ';'
1>D:\Program Files\Epic Games\Unreal Project\FPSGame\Source\FPSGame\Private\Weapon\Weapon.cpp(9): error C2065: 'CollisionComp': undeclared identifier
1>D:\Program Files\Epic Games\Unreal Project\FPSGame\Source\FPSGame\Private\Weapon\Weapon.cpp(9): error C2065: 'UBoxComponent': undeclared identifier
1>D:\Program Files\Epic Games\Unreal Project\FPSGame\Source\FPSGame\Private\Weapon\Weapon.cpp(9): error C2672: 'FObjectInitializer::CreateDefaultSubobject': no matching overloaded function found
1>D:\Program Files\Epic Games\Unreal Project\FPSGame\Source\FPSGame\Private\Weapon\Weapon.cpp(9): error C2974: 'FObjectInitializer::CreateDefaultSubobject': invalid template argument for 'TReturnType', type expected
1>D:\Program Files\Epic Games\UE_4.16\Engine\Source\Runtime\CoreUObject\Public\UObject/UObjectGlobals.h(819): note: see declaration of 'FObjectInitializer::CreateDefaultSubobject'
1>D:\Program Files\Epic Games\Unreal Project\FPSGame\Source\FPSGame\Private\Weapon\Weapon.cpp(10): error C2065: 'CollisionComp': undeclared identifier
1>D:\Program Files\Epic Games\Unreal Project\FPSGame\Source\FPSGame\Private\Weapon\Weapon.cpp(12): error C2065: 'CollisionComp': undeclared identifier
1>ERROR : UBT error : Failed to produce item: D:\Program Files\Epic Games\Unreal Project\FPSGame\Binaries\Win64\UE4Editor-FPSGame-4331.dll
1>Total build time: 19.30 seconds (Local executor: 0.00 seconds)
1>D:\Program Files\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets(44,5): error MSB3075: The command ""D:\Program Files\Epic Games\UE_4.16\Engine\Build\BatchFiles\Build.bat" FPSGameEditor Win64 Development "D:\Program Files\Epic Games\Unreal Project\FPSGame\FPSGame.uproject" -waitmutex" exited with code 5. Please verify that you have sufficient rights to run this command.