Hi,
I have my own character class, which declares a blueprint reference.
public:
UPROPERTY(EditDefaultsOnly, Category = "Soldier Setup")
TSubclassOf<class AWeapon> m_DefaultWeapon;
Which references my own actor class, AWeapon
class TAPPRASIAL_API AWeapon : public AActor
In the character class, in the OnBeginPlay, I want each character to spawn an instance of this blueprint for themselves.
// Called when the game starts or when spawned
void ASoldier::BeginPlay() {
Super::BeginPlay();
if (m_DefaultWeapon) {
FActorSpawnParameters spawnInfo;
spawnInfo.Name = TEXT("SpawnedWeapon");
spawnInfo.Owner = this;
spawnInfo.Instigator = Instigator;
FTransform ourTransform = GetTransform();
m_EquippedWeapon = GetWorld()->SpawnActor<AWeapon>(m_DefaultWeapon, ourTransform, spawnInfo);
}
}
However I am encountering 2 issues.
-
Rather than each character spawning a weapon for themselves, they all end up referencing the single instance that gets spawned in the world
-
The object spawned does not take on the name I set in the FActorSpawnParameters, but rather just the default blueprint name
If I were to comment out the line of code that specifies the name property in FActorSpawnParameters, then everything functions correctly and each character ends up with their own instance (without the ‘SpawnedWeapon’ name obviously).
Any ideas whats going wrong? Thanks in advance