So I have an enum class ECharacterState I’ve been using to store data on the player state: attacking, moving, and so forth. It worked perfectly, and let me create and read/write variables of type ECharacterState with no trouble. I’m refactoring my code, and since the only place this enum is used is in the base character class, I tried deleting it from the class it was originally in, and pasting the declaration into my BaseCharacter header:
#pragma once
#include "GameFramework/Character.h"
#include "MBaseCharacter.generated.h"
UCLASS()
class CODEPROJ_API AMBaseCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AMBaseCharacter(const class FObjectInitializer& ObjectInitializer);
UFUNCTION(BlueprintCallable, Category = "PlayerCondition")
ECharacterState characterState;
// 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;
};
UENUM(BlueprintType)
enum class ECharacterState : uint8{
Locomotion,
Attacking,
Flinching,
Nonresponsive,
Menu,
};
Ooh, I’m going to feel really silly if this works. You mean like this, right?
#pragma once
#include "GameFramework/Character.h"
#include "MBaseCharacter.generated.h"
UENUM(BlueprintType)
enum class ECharacterState : uint8{
Locomotion,
Attacking,
Flinching,
Nonresponsive,
Menu,
};
UCLASS()
class CODEPROJ_API AMBaseCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AMBaseCharacter(const class FObjectInitializer& ObjectInitializer);
UFUNCTION(BlueprintCallable, Category = "PlayerCondition")
ECharacterState characterState;
// 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;
};
That gets rid of the type error, but now it pops a different error, “Bad function definition”, for my “ECharacterState characterState;” line. I don’t need to add an #include for the enum or something, do I?
UENUM(BlueprintType)
namespace ECharacterState
{
enum State
{
Locomotion UMETA(DisplayName = "Display Name in Editor"),
Attacking UMETA(DisplayName = "Display Name in Editor"),
Flinching UMETA(DisplayName = "Display Name in Editor"),
Nonresponsive UMETA(DisplayName = "Display Name in Editor"),
Menu UMETA(DisplayName = "Display Name in Editor")
};
}
Awww, I figured it out on my own and came to post about it, and you just beat me to the punch- thank you guys!
I ended up solving it by systematically commenting out everything until it started compiling, but that was a really silly error to be making- correct macro usage for the win. ^^