x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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'

Product Version: Not Selected
Tags:
more ▼

asked Jun 28 '14 at 12:11 PM in C++ Programming

CAPTNCAPS gravatar image

CAPTNCAPS
130 26 22 29

Shadowriver gravatar image Shadowriver ♦ Jun 28 '14 at 12:28 PM

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

CAPTNCAPS gravatar image CAPTNCAPS Jun 28 '14 at 12:30 PM

I am just following this Tutorial: http://creategamesfromscratch.blogspot.de/2014/05/prototype-adding-hands-and-weapon.html

And I guess this guy knows what he does :P

Shadowriver gravatar image Shadowriver ♦ Jun 28 '14 at 12:36 PM

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

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Jun 28 '14 at 12:31 PM

Shadowriver gravatar image

Shadowriver ♦
24.1k 880 108 991

CAPTNCAPS gravatar image CAPTNCAPS Jun 28 '14 at 12:43 PM

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'"

Shadowriver gravatar image Shadowriver ♦ Jun 28 '14 at 12:56 PM

How your enum looks right now?

CAPTNCAPS gravatar image CAPTNCAPS Jun 28 '14 at 01:02 PM

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);

Shadowriver gravatar image Shadowriver ♦ Jun 28 '14 at 01:20 PM

Add varable name in function argument like this:

void ChangeWeapon_Implementation(EWeaponTypes type);

CAPTNCAPS gravatar image CAPTNCAPS Jun 28 '14 at 01:33 PM

Thanks alot!

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question