How to do it...

  1. Navigate to the C++ class that you'd like to add the UCLASS reference member to. 
  2. From inside a UCLASS, use code of the following form to declare a UPROPERTY that allows for the selection of a UClass (blueprint class) that derives from UObject in the hierarchy:
UCLASS(Blueprintable, BlueprintType)
class CHAPTER_02_API UUserProfile : public UObject
{
GENERATED_BODY()

public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Stats)
float Armor;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Stats)
float HpMax;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Stats)
FString Name;

// Displays any UClasses deriving from UObject in a dropdown
// menu in Blueprints
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Unit)
TSubclassOf<UObject> UClassOfPlayer;

// Displays string names of UCLASSes that derive from
// the GameMode C++ base class
UPROPERTY( EditAnywhere, meta=(MetaClass="GameMode"),
Category = Unit )
FStringClassReference UClassGameMode;
};
Visual Studio may underline the UClassOfPlayer variable and say that an incomplete class is not allowed. This is one of those cases when Visual Studio errors aren't right and can be ignored as it will compile fine inside UE4.
  1. Blueprint the C++ class, and then open that blueprint:

Notice that we now have a second category, Unit, and it has the two properties we specified in our script.

  1. Click on the drop-down menu beside your UClassOfPlayer menu.
  2. Select the appropriate UClassOfPlayer member from the drop-down menu of the listed UClass: