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"

Passing an Enum as Parameter into a UFUNCTION

So I am trying to create a blueprint enabled method with C++ but I am running into a Missing '*' error that is breaking solution.

 // Fill out your copyright notice in the Description page of Project Settings.

 #pragma once
 
 #include "Kismet/BlueprintFunctionLibrary.h"
 #include "CharacterStats.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class TERRAIN_API UCharacterStats : public UBlueprintFunctionLibrary
 {
     GENERATED_BODY()
     
 public:
 
     UENUM(BlueprintType)
     enum class EStat : uint8
     {
         ATTACK     UMETA(DisplayName = "Attack"),
         DEFENSE     UMETA(DisplayName = "Defense"),
         HEALTH     UMETA(DisplayName = "Health"),
         DODGE     UMETA(DisplayName = "Dodge"),
         AGILITY     UMETA(DisplayName = "Agility")
     };
     
     
     
 };


Now in my base class a am creating the function.

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "CharacterStats.h"
 #include "GameFramework/Character.h"
 #include "BaseCharacter.generated.h"
 
 
 
 UCLASS()
 class TERRAIN_API ABaseCharacter : public ACharacter
 {
     GENERATED_BODY()
 
 public:
 
     UFUNCTION(BlueprintCallable, Category = "Stats")
     void SetPlayerStat(UCharacterStats::EStat Stat, int32 Amount);
 
     // Sets default values for this character's properties
     ABaseCharacter();
 
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
     
     // Called every frame
     virtual void Tick( float DeltaSeconds ) override;
 
     // Called to bind functionality to input
     virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
     
 };


No mater what I do I keep getting "Missing '*' in Expected a pointer type" error. If I remove the UFUNCTION it compiles fine.

I get the same error exactly if I add the *

     void SetPlayerStat(UCharacterStats::EStat* Stat, int32 Amount);



Help Please!!!

Product Version: UE 4.8
Tags:
more ▼

asked Oct 07 '15 at 05:10 PM in C++ Programming

avatar image

Dtaggart
9 2 4 6

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

2 answers: sort voted first

Hey Dtaggart-

If I understand correctly you're trying to create a function that can be called inside a blueprint that takes in an Enum as a parameter? Using the Enum you posted and Shadowriver's suggestion I was able to compile a function successfully. I copied your Enum and used Shadowriver's suggestion of removing "class" and "uint8" from the Enum declaration. This was placed outside of the class declaration rather than inside. Inside the class I was able to create the following function which compiled and was usable in the editor:

 UFUNCTION(BlueprintCallable, Category = Test)
     void TestFunc(TEnumAsByte<EStat> Compiled);

alt text

Let me know if this is the functionality you are trying to achieve or if there is something I've missed about your issue.

Cheers

Doug Wilson

enumnode.png (20.6 kB)
more ▼

answered Oct 07 '15 at 09:15 PM

avatar image Dtaggart Oct 07 '15 at 10:15 PM

Moving out of the class was the Key! Working now Thanks both of you!

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

Reflection system only support specific types, thats why you get error from UHT (not compiler) when you use it with UFUNCTION().

Remove "class" and ": uint8" from enum declaration (reflection system does not support enum classes) and in function place

 TEnumAsByte<UCharacterStats::EStat> 

as well anywhere else when you use enum as varable in reflection system. I'm not sure if you can use Enum inside class, i did that myself and not sure if it's gonna work (it might build with UENUM(), because UHT ignore it thinking it some macro inside class and compiler ignore all reflection macros), if not then move it outside of class

more ▼

answered Oct 07 '15 at 06:45 PM

avatar image

Shadowriver
37.3k 936 172 1116

avatar image Dtaggart Oct 07 '15 at 07:15 PM

Thanks for explaining this. I am now seeing a "Expected the name of a previously defined enum" for

 UFUNCTION(BlueprintCallable, Category = "Stats")
 void SetPlayerStat(TEnumAsByte<UCharacterStats::EStat>  Stat, int32 Amount);


I did try to remove the UENUM(BlueprintType)

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "Kismet/BlueprintFunctionLibrary.h"
 #include "CharacterStats.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class TERRAIN_API UCharacterStats : public UBlueprintFunctionLibrary
 {
     GENERATED_BODY()
 
 public:
 
 
     UENUM(BlueprintType)
     enum EStat
     {
         ATTACK     UMETA(DisplayName = "Attack"),
         DEFENSE     UMETA(DisplayName = "Defense"),
         HEALTH     UMETA(DisplayName = "Health"),
         DODGE     UMETA(DisplayName = "Dodge"),
         AGILITY     UMETA(DisplayName = "Agility")
     };
 
 
 
 };
(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