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"

Cant use Enum inside Interface Class

I'm Trying To use my enum which created on pawn class, inside a Interface class but every time i get compile Error: Expected the name of a previously defined enum

here is my Pawn Class header codes thatimplement my interface function which is a blueprintnative event :

     #pragma once
     
     #include "CoreMinimal.h"
     #include "GameFramework/Pawn.h"
     #include "ChopperInterface.h"
     #include "Chopper.generated.h"
     
     UENUM(BlueprintType)
     enum EChopperAttackTypeEnum
     {
         None            UMETA(DisplayName = "None"),
         ChopperWeapon    UMETA(DisplayName = "Chopper Weapon"),
         GunnerWeapon    UMETA(DisplayName = "Gunner Weapon"),
         RPGWeapon        UMETA(DisplayName = "RPG Weapon"),
     };
     
     UCLASS()
     class SINCEREMEN_API AChopper : public APawn, public IChopperInterface
     {
         GENERATED_BODY()
     
     virtual void SetChopperAttackType_Implementation(TEnumAsByte NewAttackType) override;
     };

and this is my interface class:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "Engine.h"
 #include "UObject/Interface.h"
 #include "ChopperInterface.generated.h"
 
 class AChopper;
 enum EChopperAttackTypeEnum;
 
 UINTERFACE(Blueprintable, MinimalAPI)
 class UChopperInterface : public UInterface
 {
     GENERATED_BODY()
 };
 
 
 class SINCEREMEN_API IChopperInterface
 {
     GENERATED_BODY()
 
 public:
 
 UFUNCTION(BlueprintCallable, BlueprintNativeEvent, category = "Chopper Interface")
 void SetChopperAttackType(TEnumAsByte NewAttackType);
 };
 

when i remove UFUNCTION Property it compiles fine, but i need it to be BlueprintNativeEvent.

Product Version: UE 4.19
Tags:
more ▼

asked Oct 02 '18 at 10:32 AM in C++ Programming

avatar image

Mahmood215
3 1 5

avatar image Yusuf Oct 02 '18 at 12:33 PM

try enum class EChopperAttackTypeEnum:uint8 instead of enum EChopperAttackTypeEnum

avatar image Mahmood215 Oct 02 '18 at 01:34 PM

thanks for the answer, I also did that, but some how when i remove UFUNCTION property it works fine... but when i add that i get Error: Expected the name of a previously defined enum

sound weird to me...

avatar image Yusuf Oct 02 '18 at 01:49 PM

My opinion about this. TEnumAsByte not supported by the blueprint yet. Because it's a template; Try something like this:

 UFUNCTION(BlueprintNativeEvent, BlueprintCallable, category = "Chopper Interface")
  void SetChopperAttackType(EChopperAttackTypeEnum NewAttackType);

or look work around if it's possible.

avatar image Mahmood215 Oct 03 '18 at 05:21 AM

thanks yusuf, i made enum class EChopperAttackTypeEnum:uint8 in a seperate actor and use it in my class, with enum EchopperAttackType it wasnt working even in seperate class

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Place the enum in a separate header file and include it instead of forward declaring it

more ▼

answered Oct 03 '18 at 03:25 AM

avatar image

Ali Akbar
691 2 6 8

avatar image Mahmood215 Oct 03 '18 at 05:19 AM

Thanks soo much Ali Akbar, it fixed my problem i made a new actor and declare my Enum there so it works fine now

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Maybe this?

 void SetChopperAttackType(TEnumAsByte<EChopperAttackTypeEnum> NewAttackType);
more ▼

answered Oct 02 '18 at 12:02 PM

avatar image

Shiggi
147 6 7 9

avatar image Mahmood215 Oct 02 '18 at 01:37 PM

thanks shiggi for the correction, that was fool mistake, i fix that too, but still get this error

Error: Expected the name of a previously defined enum

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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