I’m trying to spawn objects from C++ code using references to blueprint objects that I’ve loaded in my classes constructor, but am running into trouble with garbage collection. I’ve tried tagging the pointers with UPROPERTY() but that causes them to become corrupt somehow so I removed it and set the objects as root instead. This works perfectly when I’m testing on Windows, but causes my application to crash immediately when I deploy to my Android tablet (Samsung Galaxy Note 10.1 2014 edition).
Header File:
//UPROPERTY(EditInstanceOnly, BlueprintReadOnly, Category = References)
TArray<UClass*> Blueprints;
//UPROPERTY(EditInstanceOnly, BlueprintReadOnly, Category = References)
UClass* defectBP;
CPP File (in the constructor):
//Load Cylinder blueprint
Blueprints.Push((UClass*)(ConstructorHelpers::FObjectFinder<UBlueprint> (TEXT("Blueprint'/Game/Blueprints/BridgeCylinder'"))).Object->GeneratedClass);
cylinderBP = Blueprints.Last();//(UClass*)cylinderBlueprint.Object->GeneratedClass;
cylinderBP->AddToRoot();
//Load Cube blueprint
Blueprints.Push((UClass*)(ConstructorHelpers::FObjectFinder<UBlueprint> (TEXT("Blueprint'/Game/Blueprints/BridgeCube'"))).Object->GeneratedClass);
cubeBP = Blueprints.Last();//(UClass*)cubeBlueprint.Object->GeneratedClass;
cubeBP->AddToRoot();
//Load I-beam blueprint
Blueprints.Push((UClass*)(ConstructorHelpers::FObjectFinder<UBlueprint>(TEXT("Blueprint'/Game/Blueprints/BridgeIBeam'"))).Object->GeneratedClass);
ibeamBP = Blueprints.Last();//(UClass*)cubeBlueprint.Object->GeneratedClass;
ibeamBP->AddToRoot();
defectBP = (UClass*)(ConstructorHelpers::FObjectFinder<UBlueprint>(TEXT("Blueprint'/Game/Blueprints/clicksphere'"))).Object->GeneratedClass;
defectBP->AddToRoot();
Any suggestion as to how to load blueprints/materials without them getting garbage collected would be appreciated.
Thanks
EDIT: On further investigation, this seems to be triggered by rooting multiple blueprints, so I included a bit more of my source.