How do I use an Enum as function Input in C++?

Hello.

I am trying to make a weapon system from a tutorial. The Tutorial is in BP, but I at least want to define my Vars and Events in C++. Me makes a function, clicks “add input” and selects an already made Enum.

Here is how I made my Enum in C++:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapons")
	enum class EWeaponTypes : short
	{
		None,
		G36C
	};

And then I try to do the function:

UFUNCTION(BlueprintImplementableEvent, Category = "Weapons")
	void ChangeWeapon(EWeaponTypes);

When I do this, I get following error: Member variable declaration: Cannot declare enum at variable declaration

So I tried moving the Enum out of my Main Class. Which results in following error: Unrecognized type ‘WeaponType’

Why enum for weapons? Why dont you use normal weapon classes insted? You can use UClass like this ASomeWeapon::StaticClass() to refrence to weapon type… you will need to do that at the end to spawn a weapon

You need to use UENUM insted of UPROPERTY on enum decleration, UPROPERTY is for varables not structures also read my comment

Note that he seeem to not declering those enums in C++ ; p anyway its kind of clucky way to do it, you should use UClass pointers insted as it more elastic

I am just following this Tutorial: Shooter Game Tutorial: Prototype - adding hands and weapon

And I guess this guy knows what he does :stuck_out_tongue:

I read your comment, and I am going to do so probably. But now I want to do it the way the tutorial says.

I used UENUM now I get “Missing ‘{’ in ‘Enum’”

I fixed it by changing “enum class EWeaponTypes” to “enum EWeaponTypes”

But now I get error: Missing Variable Name on my function.

UENUM(BlueprintType, Category = "Weapons")
enum EWeaponTypes
{
	None,
	G36C
};


//class & code


UFUNCTION(BlueprintImplementableEvent, Category = "Weapons")
	void ChangeWeapon_Implementation(EWeaponTypes);

Thanks alot!

How your enum looks right now?

Add varable name in function argument like this:

void ChangeWeapon_Implementation(EWeaponTypes type);