Im having an issue understanding how to use enums properly. I think it stems from how im trying to use them inside a struct. I looked at a few tutorials including Rama’s but nothing i do seems to work except what i did now, which only works partially. If i follow those tutorials in 4.13 i get compilation errors constantly, if i do it the way i have the class compiles and the struct does everything it is supposed to EXCEPT the enums.
[SPOILER]
// Copyright 1998-2016 Jesse Coles, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/Actor.h"
#include "BaseInventoryItem.generated.h"
USTRUCT(BlueprintType)
struct FItemInfo
{
GENERATED_BODY()
// Item Name
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString ItemName;
// Item Type
UENUM(EditAnywhere, BlueprintReadWrite)
enum ItemType {
Weapon UMETA(DisplayName="Weapon"),
Armor UMETA(DisplayName = "Armor"),
Potion UMETA(DisplayName = "Potion"),
Food UMETA(DisplayName = "Food")
};
// Weapon Wear Slot
UENUM(EditAnywhere, BlueprintReadWrite)
enum WeaponType {
OneHand UMETA(DisplayName = "One Hand"),
TwoHand UMETA(DisplayName = "Two Hand"),
Bow UMETA(DisplayName = "Bow"),
Staff UMETA(DisplayName = "Staff")
};
// Armor Wear Slot
UENUM(EditAnywhere, BlueprintReadWrite)
enum ArmorType {
Helmet UMETA(DisplayName = "Helmet"),
Chest UMETA(DisplayName = "Chest"),
Legs UMETA(DisplayName = "Legs"),
Hands UMETA(DisplayName = "Hands"),
Shoulders UMETA(DisplayName = "Shoulders"),
Feet UMETA(DisplayName = "Feet")
};
// Type of potion
UENUM(EditAnywhere, BlueprintReadWrite)
enum PotionType {
Health UMETA(DisplayName = "Health Potion"),
Mana UMETA(DisplayName = "Mana Potion"),
Stamina UMETA(DisplayName = "Stamina Potion")
};
// Level Item Can Be Used
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 ItemLevel;
// Regeneration Amount
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 BoostAmount;
// Weapon Damage Multiplyer
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 DamageMult;
// Armor Boost Amount
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 ArmorAmount;
// Food or Potion Duration
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 Duration;
};
UCLASS()
class ODDARON_API ABaseInventoryItem : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ABaseInventoryItem();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Details")
FItemInfo Item_Info;
};
To be honest, I’m surprised the Unreal Header Tool doesn’t just blow up. EditAnywhere and BlueprintReadWrite aren’t valid UENUM specifiers (unless this has changed in 4.12 or 4.13?).
Unless I’m missunderstanding your problem:
Your struct does not actually have any properties of those enums.
What you probably intended was this
thanks for your reply, it wont compile like that unfortuantely
Error E:/UE4 Projects/Oddaron/Source/Oddaron/BaseInventoryItem.h(51) : You cannot use the raw enum name as a type for member variables, instead use TEnumAsByte or a C++11 enum class with an explicit underlying type (currently only uint8 supported).
i will dig into it a bit after work i guess, its tough cause ive been finding a lot of documentation changed with these newer versions.
I had deleted the entire bp class and recreated it. I don’t care a lot about blueprint functionality, what I want is when I’m creating these items from the base class I can just pick from a dropdown if its a weapon and what type and such for fast item creation in the details panel. Any functionality will likely be done after any checks for that so I wont need to get into the enums in BP Graph.
The implementation you used @Vindomire is the old style namespaced enums. Using namespaced enums with TEnumAsByte properties will work just fine. Epic also recommends enums used similar to what @UnrealEverything suggested.
// Outside of your struct
// Old enum
UENUM()
namespace EThing
{
enum Type
{
Thing1,
Thing2
};
}
// New enum
UENUM()
enum class EThing : uint8
{
Thing1,
Thing2
};
// In your struct
// Old property
UPROPERTY()
TEnumAsByte<EThing::Type> MyProperty;
// New property
UPROPERTY()
EThing MyProperty;