Hello all,
I’ve been working on a simple shooter game in UE4, and I have created an enumerated type that I would like to be usable across all of my game’s classes. Currently the enumerated type lives inside of the header file for my player’s character class “MNCharacter.h”
MNCharacter.h
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "MN.h"
#include "MNCharacter.generated.h"
UENUM(BlueprintType)
namespace EWeaponTypes
{
enum Type{
Unarmed UMETA(DisplayName = "Unarmed"),
Pistol UMETA(DisplayName = "Pistol"),
AssaultRifle UMETA(DisplayName = "AssaultRifle"),
TacRifle UMETA(DisplayName = "TacticalRifle"),
Shotgun UMETA(DisplayName = "Shotgun"),
Sniper UMETA(DisplayName = "SniperRifle"),
Rockets UMETA(DisplayName = "RocketLauncher")
};
}
UCLASS(config=Game)
class AMNCharacter : public ACharacter
{
GENERATED_UCLASS_BODY()
//***Component Properties**
/** Pawn mesh: 1st person view (arms; seen only by self) */
UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
TSubobjectPtr<class USkeletalMeshComponent> Mesh1P;
/** Pawn mesh: 3rd person view (full body; seen by other players) */
UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
TSubobjectPtr<class USkeletalMeshComponent> Mesh3P;
/** First person camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
TSubobjectPtr<class UCameraComponent> FirstPersonCameraComponent;
//***Turning Variables**
/** Base turn rate, in deg/sec. Other scaling may affect final turn rate. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
float BaseTurnRate;
/** Base look up/down rate, in deg/sec. Other scaling may affect final rate. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
float BaseLookUpRate;
//***Weapon and Projectile**
/** Gun muzzle's offset from the characters location */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
FVector GunOffset;
/** Projectile class to spawn */
UPROPERTY(EditDefaultsOnly, Category = Projectile)
TSubclassOf<class AMonkeyNutsProjectile> ProjectileClass;
/** Sound to play each time we fire */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
USoundBase* FireSound;
/** AnimMontage to play each time we fire */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
UAnimMontage* FireAnimation;
//***Player Variables**
//**********Function Prototypes**********
UFUNCTION()
int32 GetHealth();
UFUNCTION()
int32 GetEquippedAmmo_Remaining();
UFUNCTION()
int32 GetEquippedAmmoClip_Remaining();
UFUNCTION()
int32 GetEquippedAmmoClip_Max();
UFUNCTION()
int32 GetBackupAmmo_Remaining();
UFUNCTION()
int32 GetBackupAmmoClip_Remaining();
UFUNCTION()
int32 GetBackupAmmoClip_Max();
UFUNCTION()
int32 GetGrenade_Ammo();
UFUNCTION()
TEnumAsByte<EWeaponTypes::Type> GetCurrentWeapons();
UFUNCTION()
TEnumAsByte<EWeaponTypes::Type> GetEquippedWeapon();
UFUNCTION()
TEnumAsByte<EWeaponTypes::Type> GetBackupWeapon();
UFUNCTION()
void Tick(float DeltaSeconds) override;
private:
UPROPERTY(EditAnywhere, Instanced, Category = PlayerStatus)
int32 PlayerHealth;
UPROPERTY(EditAnywhere, Instanced, Category = PlayerEquipment)
TEnumAsByte<EWeaponTypes::Type> EquippedWeapon;
UPROPERTY(EditAnywhere, Instanced, Category = PlayerEquipment)
TEnumAsByte<EWeaponTypes::Type> BackupWeapon;
//Stores which carried weapon is currently equipped. 1 for Primary, 2 for Secondary.
UPROPERTY(EditAnywhere, Instanced, Category = PlayerEquipment)
int32 CurrentWeapon;
//Total Amount of Ammo Stockpiled for Current Weapon
UPROPERTY(EditAnywhere, Instanced, Category = PlayerEquipment)
int32 Equipped_Ammo_Remaining;
//Amount of Ammo Remaining in the Current Clip
UPROPERTY(EditAnywhere, Instanced, Category = PlayerEquipment)
int32 Equipped_AmmoClip_Remaining;
//Maximum Amount of Ammo Possible in Current Clip
UPROPERTY(EditAnywhere, Instanced, Category = PlayerEquipment)
int32 Equipped_AmmoClip_Max;
//Total Amount of Ammo Stockpiled for Current Weapon
UPROPERTY(EditAnywhere, Instanced, Category = PlayerEquipment)
int32 Backup_Ammo_Remaining;
//Amount of Ammo Remaining in the Current Clip
UPROPERTY(EditAnywhere, Instanced, Category = PlayerEquipment)
int32 Backup_AmmoClip_Remaining;
//Maximum Amount of Ammo Possible in Current Clip
UPROPERTY(EditAnywhere, Instanced, Category = PlayerEquipment)
int32 Backup_AmmoClip_Max;
//Number of Grenades Avaliable
UPROPERTY(EditAnywhere, Instanced, Category = PlayerEquipment)
int32 Grenade_Ammo;
protected:
/** Handler for a touch input beginning. */
void TouchStarted(const ETouchIndex::Type FingerIndex, const FVector Location);
/** Fires a projectile. */
void OnFire();
/** Handles moving forward/backward */
void MoveForward(float Val);
/** Handles stafing movement, left and right */
void MoveRight(float Val);
/**
* Called via input to turn at a given rate.
* @param Rate This is a normalized rate, i.e. 1.0 means 100% of desired turn rate
*/
void TurnAtRate(float Rate);
/**
* Called via input to turn look up/down at a given rate.
* @param Rate This is a normalized rate, i.e. 1.0 means 100% of desired turn rate
*/
void LookUpAtRate(float Rate);
// APawn interface
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
// End of APawn interface
};
Currently I have been including this character header file in every class that I wish to use my enumerated type in, and currently I have a lot of code which uses the enumerated type. This code currently functions properly.
However, because all of my game’s classes require the inclusion of MN.h (my game’s core class), I would like to move the declaration of my enumerated type to the core class header (MN.h). When I do this, (as shown below) Visual Studio gives me “Error code: 2” and “error MSB3073: The command ““C:\Program Files\Unreal Engine\4.4\Engine\Build\BatchFiles\Build.bat” MNEditor Win64 Development “C:\Users\BS\Documents\Unreal Projects\MN\MN.uproject” -rocket” exited with code -1.”
MN.h
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#ifndef __MN_H__
#define __MN_H__
#include "Engine.h"
#include "Kismet/GameplayStatics.h"
#define COLLISION_PROJECTILE ECC_GameTraceChannel1
#endif
UENUM(BlueprintType)
namespace EWeaponTypes
{
enum Type{
Unarmed UMETA(DisplayName = "Unarmed"),
Pistol UMETA(DisplayName = "Pistol"),
AssaultRifle UMETA(DisplayName = "AssaultRifle"),
TacRifle UMETA(DisplayName = "TacticalRifle"),
Shotgun UMETA(DisplayName = "Shotgun"),
Sniper UMETA(DisplayName = "SniperRifle"),
Rockets UMETA(DisplayName = "RocketLauncher")
};
}
Could someone enlighten me on why this won’t work?
Thanks in advance.