Syntax Error when using accepting an Enum as a param

I have defined an enumeration at the top of a UQuakeWeapon.h file that looks like this:

UENUM(BlueprintType)
enum class EAmmoType : uint8
{
    ENone       UMETA(DisplayName="None"),
    EShell      UMETA(DisplayName="Shells"),
    ENail       UMETA(DisplayName="Nails")
};

I have a series of ammo integers in my player class, and I’m trying to have a weapon call a GetAmmo method in the player class when fired. The GetAmmo() and SetAmmo() methods in the header look like this:

int32 GetAmmo(EAmmoType ammoType);

void SetAmmo(EAmmoType ammoType, int32 value);

However, when I compile this code, Unreal throws:

syntax error: identifier 'EAmmoType'

on both of those methods. The player header class includes the UQuakeWeapon.h. I’m not sure why Unreal is throwing a syntax error here.

If I understand your setup correctly, you are defining your enum in your weapon class and calling the functions (which take your enum as a parameter) in your character class, is that correct? Was a definition for the two classes added to the Character.cpp file? Is there a reference to EAmmoType anywhere else in the project? Can you provide the full output log from Visual Studio?

I’m defining the enum above the UCLASS() macro in my weapon header, and those functions exist in my character class, which has an #include “UQuakeWeapon.h” statement. EAmmoType is not referenced anywhere else, other than UQuakeWeapon.cpp and UQuakeCharacter.h/cpp. Visual Studio produces this pastebinned output.

It does occur to me that UQuakeCharacter.h includes UQuakeWeapon.h, and UQuakeWeapon.h includes UQuakeCharacter.h. Could a circular dependency be causing this error? I’m not sure if it is, because they’ve included each other for a long time, and so far, the project has been compiling fine.

Circular dependency appears to be the most likely cause of the compile errors. Without seeing the setup of your classes, the best solution would be to remove the include statement from one class and replace it with a forward declaration for the necessary class. In this case I would try removing the Character class include from your Weapon class and use class AUQuakeCharacter instead.

Cheers

Yep, that fixed it! I knew the circular dependency had existed for a while, but it seemed to compile fine before now. I’ll watch out for them in the future.

Only downside is I now need to include the UQuakeCharacter header in all of my weapon CPPs. But hey, at least it compiles!