You probably already have a reference to the pistol actor in your class. If not, you can declare it in the header file like this:
TSubclassOf<class AActor> MyPistol;
In the constructor, you need to tell FObjectFinder what type of class to expect, in this case UBlueprint. Then spawn an actor with the found object as template. You might want to add a check to make sure the object was actually found (in case you ever change the path):
static ConstructorHelpers::FObjectFinder<UBlueprint> PistolBP(TEXT("Blueprint'/Game/FirstPersonCPP/Blueprints/Pickup/Pistol'"));
if (PistolBP)
{
MyPistol = GetWorld()->SpawnActor(PistolBP.Object->GetClass());
}
Actually, for Blueprints the path might have to look like this: Blueprint’/Game/FirstPersonCPP/Blueprints/Pickup/Pistol.Pistol’
You can also use the ClassFinder directly, which works pretty similar to the ObjectFinder:
static ConstructorHelpers::FClassFinder<UBlueprint> PistolBP(TEXT("Blueprint'/Game/FirstPersonCPP/Blueprints/Pickup/Pistol'"));
if (PistolBP)
{
MyPistol = GetWorld()->SpawnActor(PistolBP.Class);
}
Okay, from what I gather is that you have a c++ PlayerCharacter class and that you setup your weapons as a c++ AWeapon class that you then create blueprints for.
Why not just create a member in the PlayerCharater class and expose it to blueprints. Then create a blueprint for PlayerCharacter, and then set the weapons there.
For example, in PlayerCharacter:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Guns, meta=(AllowPrivateAccess = "true"))
class UClass* Weapon;
Then when you have BP_PlayerCharacter, you should see the property in the editor window.
If it is really something you need to spawn, then do something like:
FVector SpawnLocation = GetActorLocation();
UWorld* const World = GetWorld();
if (World != NULL) {
if (Weapon) {
World->SpawnActor<AWeapon>(Weapon, SpawnLocation, GetActorRotation());
}
}
This is basically what I do for weapon projectiles.