UCLASS()
class SPACE_PROTOTYPE_API AWgBlueprint : public AActor
{
GENERATED_UCLASS_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Equipment")
TSubclassOf<AEquipment> EquipmentClass;
};
Basing on it, I’m creating a blueprint in editor and setting EquipmentClass to some default value (doesn’t matter). So this information stored in blueprint in editor.
How can I access to value of my parameter through C++ code without spawning a blueprint ?
I’m no expert but here’s the method I use and it seems to work fine.
//you need to find the UClass of your blueprint. StaticLoadClass finds it via the path name and it works outside of constructors,
//if you're using this code in a constructor you should use ConstructorHelpers::FObjectFinder instead
UClass *BPClass = StaticLoadClass(AActor::StaticClass(), NULL, TEXT("/Game/Blueprints/MyBlueprint.MyBlueprint_C"));
//if we found the blueprints UClass, we can then access the default object that UE4 creates for all its object types
if (BPClass){
AWgBlueprint *DefaultObject = BPClass->GetDefaultObject<AWgBlueprint>();
if (DefaultObject){
//and now DefaultObject points to an object with the blueprints default values
UClass *DefaultEquipmentClass = DefaultObject->EquipmentClass;
}
}
StaticLoadClass and FObjectFinder use slightly different path arguments, for StaticLoadClass use “/Path/Goes/Here/BP.BP_C”, and for FObjectFinder use "Class’/Path/Goes/Here/BP.BP_C’ "
Don’t modify the default object in any way, bad things will happen.