Actor won't spawn

Hi, I am trying to make a weapon respawn point to be put onto the level. The problem is it will not spawn the weapon again after the initial spawn. I will have the codes posted here:

void AWeaponSpawner::BeginPlay()
{
	Super::BeginPlay();
	SpawnMech();
}

// ...


void AWeaponSpawner::NotifyActorBeginOverlap(AActor* OtherActor)
{
	Super::NotifyActorBeginOverlap(OtherActor);

	if (!IsOverlappingActor(OtherActor))
	{
		GetWorldTimerManager().SetTimer(RespawnTimer, this, &AWeaponSpawner::SpawnMech, CoolDown, false);
	}
}

void AWeaponSpawner::SpawnMech()
{
	if (WeaponClass != nullptr)
	{
		FActorSpawnParameters PowerUpParams;
		PowerUpParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::DontSpawnIfColliding;
		WeaponToSpawn = GetWorld()->SpawnActor<AActor>(WeaponClass, GetTransform(), PowerUpParams);
		
	}

}

The actual weapon I am trying to spawn was set to overlap all actors except the trace collision I have for my player(customized collision channel), and once the player overlaps with the weapon, it can be picked up by pressing E, and the weapon mesh will be attached to player’s mesh component.
Right now, after the initial spawn in begin play, the weapon will not spawn.

Thanks in advance!

This is risky. You probably want to respawn it always regardless of collision, or check that collision is not the problem.

Which, the one on BeginPlay? Does NotifyActorBeginOverlap execute at all? Does the timer work?

I suggest you debug this code with Visual Studio, which you can attach to the UE4 process and use to walk through breakpoints.

1 Like

Your NotifyActorBeginOverlap is called and then you test IsOverlappingActor. Won’t this test always return true and hence your timer will never be started?

1 Like