Download

Structs, Enums and BP/Editor

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


[/SPOILER]

8b72756db6844292b051590aa2bf1736.png
e2c70253303541e9acc94bf98d7be3b8.png

Im getting the non ENUM values showing up in the editor and in the struct break but not the enums… if someone could point me in the right direction…

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


UENUM()
enum EItemType {
	IT_Weapon		UMETA(DisplayName="Weapon"),
	IT_Armor		UMETA(DisplayName = "Armor"),
	IT_Potion		UMETA(DisplayName = "Potion"),
	IT_Food			UMETA(DisplayName = "Food")
};

UENUM()
enum EWeaponType {
	WT_OneHand		UMETA(DisplayName = "One Hand"),
	WT_TwoHand		UMETA(DisplayName = "Two Hand"),
	WT_Bow			UMETA(DisplayName = "Bow"),
	WT_Staff		UMETA(DisplayName = "Staff")
};

UENUM()
enum EArmorType {
	AT_Helmet		UMETA(DisplayName = "Helmet"),
	AT_Chest		UMETA(DisplayName = "Chest"),
	AT_Legs			UMETA(DisplayName = "Legs"),
	AT_Hands		UMETA(DisplayName = "Hands"),
	AT_Shoulders		UMETA(DisplayName = "Shoulders"),
	AT_Feet			UMETA(DisplayName = "Feet")
};

UENUM()
enum EPotionType {
	PT_Health		UMETA(DisplayName = "Health Potion"),
	PT_Mana			UMETA(DisplayName = "Mana Potion"),
	PT_Stamina		UMETA(DisplayName = "Stamina Potion")
};

USTRUCT(BlueprintType)
struct FItemInfo
{
	GENERATED_BODY()

		// Item Name
		UPROPERTY(EditAnywhere, BlueprintReadWrite)
			FString ItemName;
		// Item Type


		UPROPERTY(EditAnywhere, BlueprintReadWrite)
			EItemType ItemType;
		// Weapon Wear Slot
		UPROPERTY(EditAnywhere, BlueprintReadWrite)
			EWeaponType WeaponType;
		// Armor Wear Slot
		UPROPERTY(EditAnywhere, BlueprintReadWrite)
			EArmorType ArmorType;
		// Type of potion
		UPROPERTY(EditAnywhere, BlueprintReadWrite)
			EPotionType PotionType;


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

};

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.

[SPOILER]



// Copyright 1998-2016 Jesse Coles, Inc. All Rights Reserved.

#pragma once
#include "GameFramework/Actor.h"
#include "BaseInventoryItem.generated.h"

UENUM()
enum EItemType {
	IT_Weapon		UMETA(DisplayName = "Weapon"),
	IT_Armor		UMETA(DisplayName = "Armor"),
	IT_Potion		UMETA(DisplayName = "Potion"),
	IT_Food			UMETA(DisplayName = "Food")
};

UENUM()
enum EWeaponType {
	WT_OneHand		UMETA(DisplayName = "One Hand"),
	WT_TwoHand		UMETA(DisplayName = "Two Hand"),
	WT_Bow			UMETA(DisplayName = "Bow"),
	WT_Staff		UMETA(DisplayName = "Staff")
};

UENUM()
enum EArmorType {
	AT_Helmet		UMETA(DisplayName = "Helmet"),
	AT_Chest		UMETA(DisplayName = "Chest"),
	AT_Legs			UMETA(DisplayName = "Legs"),
	AT_Hands		UMETA(DisplayName = "Hands"),
	AT_Shoulders	UMETA(DisplayName = "Shoulders"),
	AT_Feet			UMETA(DisplayName = "Feet")
};

UENUM()
enum EPotionType {
	PT_Health		UMETA(DisplayName = "Health Potion"),
	PT_Mana			UMETA(DisplayName = "Mana Potion"),
	PT_Stamina		UMETA(DisplayName = "Stamina Potion")
};

USTRUCT(BlueprintType)
struct FItemInfo
{
	GENERATED_BODY()

	// Item Name
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FString ItemName;

	// Item Type

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TEnumAsByte<EItemType> ItemType;
	// Weapon Wear Slot
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TEnumAsByte<EWeaponType> WeaponType;	// Armor Wear Slot
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TEnumAsByte<EArmorType> ArmorType;
	// Type of potion
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TEnumAsByte<EPotionType> PotionType;


	// 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;
};


[/SPOILER] This works to compile but still no enums.

Did you refresh (or recreate) the break node already? If not try that (it’s one of the options in the context menu when right-clicking a node).

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.

ok i got it working, will post what i did in a few hours when im home from work.

This is how i got it to work.

d1053e842c90d6cefa7e534536221024beed378d.png

BaseItem.h
[SPOILER]



// Copyright 1998-2016 Jesse Coles, Inc. All Rights Reserved.

#pragma once
#include "Enum_ItemEnums.h"
#include "GameFramework/Actor.h"
#include "BaseInventoryItem.generated.h"

USTRUCT(BlueprintType)
struct FItemInfo
{
	GENERATED_BODY()

	// Item Name
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FString ItemName;

	// Item Type
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TEnumAsByte<EItemType::ItemType> ItemType;
	// Weapon Wear Slot
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TEnumAsByte<EWeaponType::WeaponType> WeaponType;	// Armor Wear Slot
	// Armor Wear Slot
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TEnumAsByte<EArmorType::ArmorType> ArmorType;
	// Type of potion
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TEnumAsByte<EPotionType::PotionType> PotionType;


	// 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;
};


[/SPOILER]

Enum .h
[SPOILER]



// Copyright 1998-2016 Jesse Coles, Inc. All Rights Reserved.

#pragma once

#include "Engine/UserDefinedEnum.h"
#include "Enum_ItemEnums.generated.h"

UENUM(BlueprintType)
namespace EItemType {
	enum ItemType {
		IT_Weapon		UMETA(DisplayName = "Weapon"),
		IT_Armor		UMETA(DisplayName = "Armor"),
		IT_Potion		UMETA(DisplayName = "Potion"),
		IT_Food			UMETA(DisplayName = "Food")
	};
}

UENUM(BlueprintType)
namespace EWeaponType {
	enum WeaponType {
		WT_OneHand		UMETA(DisplayName = "One Hand"),
		WT_TwoHand		UMETA(DisplayName = "Two Hand"),
		WT_Bow			UMETA(DisplayName = "Bow"),
		WT_Staff		UMETA(DisplayName = "Staff")
	};
}


UENUM(BlueprintType)
namespace EArmorType {
	enum ArmorType {
		AT_Helmet		UMETA(DisplayName = "Helmet"),
		AT_Chest		UMETA(DisplayName = "Chest"),
		AT_Legs			UMETA(DisplayName = "Legs"),
		AT_Hands		UMETA(DisplayName = "Hands"),
		AT_Shoulders	UMETA(DisplayName = "Shoulders"),
		AT_Feet			UMETA(DisplayName = "Feet")
	};
}

UENUM(BlueprintType)
		namespace EPotionType {
		enum PotionType {
		PT_Health		UMETA(DisplayName = "Health Potion"),
		PT_Mana			UMETA(DisplayName = "Mana Potion"),
		PT_Stamina		UMETA(DisplayName = "Stamina Potion")
	};
}

/**
 * 
 */
UCLASS()
class ODDARON_API UEnum_ItemEnums : public UUserDefinedEnum
{
	GENERATED_BODY()
	
	
	
	
};


[/SPOILER]

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;


Here’s a link to Epic’s coding standard where they go over this as well as mention other things such as using bitmasks, etc: https://docs.unrealengine.com/latest/INT/Programming/Development/CodingStandard/#strongly-typedenums