//--------Shooter.h--------------
public:
UPROPERTY(EditDefaultsOnly, Category = Equipment)
TSubclassOf<AGun> WeaponSubclass;
//----------------Shooter.cpp (constructor)-----------------------------------------
UWorld* World = GetWorld();
if (World)
{
if (WeaponSubclass)
{
FActorSpawnParameters SpawnParams;
Weapon = World->SpawnActor<AGun>(WeaponSubclass, SpawnParams);
if (Weapon)
{
Weapon->AttachRootComponentTo(GetMesh(), WeaponSocketName, EAttachLocation::SnapToTarget);
}
}
}
I set “WeaponSubclass” in the editor to an AGun blueprint, but whenever I run the game, WeaponSubclass is null.