Download

How to Spawn an Actor with a Blueprint template?

I want to convert this so it takes a reference i map in the character BP so it spawns the child class i made for ease of use instead of the C++ version. Whats the simplest way i can do this? I’ve already mapped the variable in the header to the weapon class it then compiles but when i use the variable it reports as a null pointer?

Header File



UPROPERTY(EditAnyWhere, BluePrintReadWrite, Category = SaveSystem)
		TSubclassOf<class AWeapon_AmberPistol> WeaponPistol;


This version spawns the base C++ version of the gun which i dont want, since all the particle effects/sounds are mapped to the BP child version



	AWeapon_AmberPistol* WeapontoSpawnPlayer = GetWorld()->SpawnActor<AWeapon_AmberPistol>(AWeapon_AmberPistol::StaticClass());
		CreateWeapon(WeapontoSpawnPlayer, SlotNum);


How i got it to spawn with the BP template but it comes back as a null pointer and crashes the engine?



AWeapon_AmberPistol* WeapontoSpawnPlayer = GetWorld()->SpawnActor<AWeapon_AmberPistol>(WeaponPistol->GetClass());


206392f822f6c93bfb85c6cc0480607716a6ffff.png

nvm i solved it by looking at the ShooterDemo Code




AWeapon_AmberPistol* WeapontoSpawnPlayer = GetWorld()->SpawnActor<AWeapon_AmberPistol>(WeaponPistol, SpawnInfo);