Converting Blueprint Structs

In this part, we are giong to convert the FQuestInfo BP Struct to C++

../../_images/fquestinfo_thumb.PNG ../../_images/fquestinfo.PNG
  1. Rename FQuestInfo to FQuestInfo_Deprecated

  2. Create new C++ class. Choose Show All Classes -> Object to create a UObject. Name it QuestInfo.

../../_images/new_cpp_class_uobject.PNG
  1. In QuestInfo.h change UCLASS to USTRUCT, removed inheritance of UOBject, change class to struct and change UQuestInfo to FQuestInfo

UCLASS()
struct BLUEPRINTSTOCPP_API FQuestInfo
USTRUCT(BlueprintType)
class BLUEPRINTSTOCPP_API FQuestInfo
  1. Add the body of QuestInfo struct.

USTRUCT(BlueprintType)
struct BLUEPRINTSTOCPP_API FQuestInfo
{
   GENERATED_BODY()

   UPROPERTY(EditAnywhere, BlueprintReadWrite)
   FString Name;

   UPROPERTY(EditAnywhere, BlueprintReadWrite)
   FName QuestId;

   UPROPERTY(EditAnywhere, BlueprintReadWrite)
   int32 Progress;

   UPROPERTY(EditAnywhere, BlueprintReadWrite)
   int32 ProgressTotal;
};

In my case UE4 would crash and so require launching again.

  1. Include QuestInfo.h in QuestManager.h

#include "QuestInfo.h"
  1. Add protected UPROPERTY to

protected:
   UPROPERTY(EditAnywhere, BlueprintReadWrite)
   TArray<FQuestInfo> QuestList;
  1. Rename variable QuestList to QuestList_Deprecated

  2. In BP_QuestManager Blueprint -> Class Defaults, replace QuestList with the new one. Unforunately, we’ll have to copy and paste each item over.

../../_images/quest_manager_default_quest_list.PNG
  1. Find all references to QuestList_Deprecated and fix them.

GetQuest is slightly more tricky it’s interface expect return of QuestInfo_Deprecated.

We could either migrate all uses of GetQuest or we can convert our C++ QuestInfo to QuestInfo_Deprecated.

../../_images/get_quest_rewired.PNG

Now go through all other references of QuestList_Deprecated and replace with QuestList.

Where the graph is large and uses get on QuestList_Deprecated, we could always be lazy and replace it with GetQuests that we created.