In one of my classes, I hold a few class pointers to blueprints in my game. I use the following code to do so:
.h
TSubclassOf<class AItem> BlueprintChair;
TSubclassOf<class AItem> BlueprintLamp;
.cpp (In the constructor)
static ConstructorHelpers::FObjectFinder<UBlueprint> ChairBlueprint(TEXT("Blueprint'/Game/Item/Chair.Chair'"));
if (ChairBlueprint.Object)
BlueprintChair = (UClass*)ChairBlueprint.Object->GeneratedClass;
static ConstructorHelpers::FObjectFinder<UBlueprint> LampBlueprint(TEXT("Blueprint'/Game/Item/Lamp.Lamp'"));
if (LampBlueprint.Object)
BlueprintLamp = (UClass*)LampBlueprint.Object->GeneratedClass;
The code works fine, but the issue becomes overhead. Every time the class is instanced, it will carry overhead for the two TSubclassOf<>. If there was only a few of these objects, that would be okay, but my game has thousands of instances making it unnecessary overhead. Is it possible to make the two TSubclassOf<> static objects, and if so, how would I go about doing so? I can’t initialize them as I normally would with static objects because they need to be set in the constructor since I use ConsructorHelpers.