When each actor tries to spawn a blueprint instance, they all refer to the same one


I have my own character class, which declares a blueprint reference.

	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() {

	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.

  1. Rather than each character spawning a weapon for themselves, they all end up referencing the single instance that gets spawned in the world

  2. 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

I think you can’t have the same name for objects because they must be unique. The spawner function will try to optimize it by returning the object with the same name.

Don’t give them a name which will automatically create a unique name or create a unique name generator.