Whether or not this is a full on bug, or something I don’t understand about C++. But from what I gather, it seems to lean on the side of bug/fluke.
Everytime I try to compile with my custom Pawn/Character class included into my header file. I get a “Unreal Header Generation Tool has stopped working” crash (Windows 7 -64bit) while trying to use the Build option off of Visual Studio 2013.
My assumption is that there is some sort of overlapping inclusion from both ROTWeapon and ROTPlayerSoldier referrencing each other, and it probably doesn’t like it or ends up in an endless loop (just guessing). I tried using #ifndef even though #pragma once is engaged, which SHOULD stop this from including the files multiple times. But to no luck.
#ifndef “ROTWeapon.h”
#define “ROTWeapon.h”
#endif
Here are my files + the crash screenshot.
ROTWeapon.h
#pragma once
#include "ROTInvManager.h"
#include "ROTPlayerSoldier.h" //Currently causing a crash
#include "ROTBullet.h"
#include "ROTInventoryItem.h"
#include "ROTWeapon.generated.h"
/**
*
*/
UCLASS(Blueprintable)
class AROTWeapon : public AROTInventoryItem
{
GENERATED_UCLASS_BODY()
UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "Weapon")
TSubclassOf<class AROTBullet> Caliber;
void BeginFire();
void EndFire();
protected:
AROTPlayerSoldier* Instigator;
};
ROTWeapon.cpp
#include "ROT.h"
#include "ROTWeapon.h"
AROTWeapon::AROTWeapon(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
void AROTWeapon::BeginFire()
{
if(GEngine)
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::White, TEXT("BANG"));
}
void AROTWeapon::EndFire()
{
}
ROTPlayerSoldier.h
#pragma once
#include "ROTWeapon.h"
#include "ROTInventoryItem.h"
#include "GameFramework/Character.h"
#include "ROTPlayerSoldier.generated.h"
/**
*
*/
UCLASS()
class AROTPlayerSoldier : public ACharacter
{
GENERATED_UCLASS_BODY()
//Character components
UPROPERTY()
TSubobjectPtr<class UCameraComponent> CameraComponent;
//Meshes (Default "Mesh" - Main body mesh that acts as a Parent for all other meshes)
UPROPERTY()
TSubobjectPtr<class USkeletalMeshComponent> HeadMesh; //Head/Face
UPROPERTY()
AROTInventoryItem* EquippedItem; //The active item
UFUNCTION(Exec)
void GiveItem();
//Movement
UFUNCTION()
virtual void MoveForward(float Value);
UFUNCTION()
virtual void MoveRight(float Value);
UFUNCTION(Exec)
void AdjustWalkSpeed(float Value);
virtual void BeginPlay();
//Called on server only when the Pawn becomes Possessed
virtual void PossedBy(class AController* NewController);
UFUNCTION()
void BeginFire();
UFUNCTION()
void EndFire();
};
ROTPlayerSoldier.cpp
#include "ROT.h"
#include "ROTPlayerSoldier.h"
AROTPlayerSoldier::AROTPlayerSoldier(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
//Movement
CharacterMovement->MaxWalkSpeed = 150;
//=== Components ===
RootComponent = CapsuleComponent;
//Collision Info
CapsuleComponent->InitCapsuleSize(16, 48);
//Camera info
CameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("CameraComponent"));
CameraComponent->AttachParent = RootComponent;
CameraComponent->SetRelativeLocation(FVector(0, 0, 40));
//=== Inventory && Character Loading ====
//Mesh information
static ConstructorHelpers::FObjectFinder<USkeletalMesh> TempMesh (TEXT("/Game/Characters/SK_CH_Characters_JackSkellieton.SK_CH_Characters_JackSkellieton"));
Mesh->SkeletalMesh = (USkeletalMesh*)TempMesh.Object;
Mesh->RelativeLocation = FVector(0, 0, -44);
Mesh->RelativeRotation = FRotator(0, -90, 0);
HeadMesh = PCIP.CreateOptionalDefaultSubobject<USkeletalMeshComponent>(this, TEXT("HeadMesh"));
HeadMesh->AttachParent = Mesh;
static ConstructorHelpers::FObjectFinder<USkeletalMesh> TempMesh1(TEXT("/Game/Characters/SK_CH_Characters_HeadTest.SK_CH_Characters_HeadTest"));
HeadMesh->SkeletalMesh = (USkeletalMesh*)TempMesh1.Object;
//Inventory
}
void AROTPlayerSoldier::BeginFire()
{
if (!EquippedItem)
return;
Cast<AROTWeapon>(EquippedItem)->BeginFire();
}
void AROTPlayerSoldier::EndFire()
{}
void AROTPlayerSoldier::BeginPlay()
{
}
void AROTPlayerSoldier::PossedBy(class AController* NewController)
{
}
void AROTPlayerSoldier::MoveForward(float Value)
{
}
void AROTPlayerSoldier::MoveRight(float Value)
{
}
void AROTPlayerSoldier::AdjustWalkSpeed(float Value)
{
CharacterMovement->MaxWalkSpeed = Value;
}
void AROTPlayerSoldier::GiveItem()
{
//static ConstructorHelpers::FObjectFinder<UClass> WeapTest(TEXT("Class'/Game/Weapons/M4A1/BP_WP_M4A1.BP_WP_M4A1'"));
//static ConstructorHelpers::FObjectFinder<UBlueprint> WeapBP(TEXT("Blueprint'/Game/Weapons/M4A1/BP_WP_M4A1.BP_WP_M4A1'"));
EquippedItem = GetWorld()->SpawnActor<AROTWeapon>(AROTWeapon::StaticClass());
//WeapTest2 = (UClass*)WeapTest.Object->GeneratedClass;
//EquippedItem = GetWorld()->SpawnActor<AROTWeapon.
}