Spawning Projectile Causes Crash

Hi, I have a class that spawns projectiles to shoot. I noticed that whenever the actor is immediately next to another actor and shoots it crashes the game. I figure it is because it is trying to spawn in a location/transform that is already occupied. I tried messing with spawn parameters to see if that would fix the problem but it doesn’t.

I know there has to be a simple solution to this but I cannot figure out what it is for the life of me. Any help would be appreciated. Thanks (I don’t know if this matters but the game is in 2D, but the physics and should be the same)

Here is my code:

void Ranged::ShootAttack()
{
	//Shoot
	FActorSpawnParameters SpawnParams;
	SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::DontSpawnIfColliding;
	AP_Bullet* NewBullet = GetWorld()->SpawnActor<AP_Bullet>(BasicBullet, PlayerShootArrow->GetComponentTransform(), SpawnParams);
	NewBullet->Damage = this->Damage;
}

Is it on Multiplayer ???

If it is, you must create another blueprint of the projectile but without the events, then you must spawn the projectile (without the events) in the proprietary client (you) and spawn the Multicast projectile only with remote authority to spawn for everyone and not for you, then create dispatch events so that anything that happens with the spawned projectile for everyone happens also with the projectile that you spawn for yourself.

You can also spawn on the server only and for no one and make everyone spawn the projectile only for yourself and link it only to the projectile visible only on the server.

It isn’t. However I found the line of code that’s crashing is the fact that I am calling destroy on the actor once it overlaps. So I believe the bullet is being destroyed faster than it can spawn (or something of that nature.) I will see what is a clear fix if I can.

Okay, So i found and fixed the problem. The issue was that I was referencing the bullet after it was destroyed (Because the bullet was being destroyed immediately.) here is my Solution:

//Shoot
	FActorSpawnParameters SpawnParams;
	SpawnParams.Owner = this;
	SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::DontSpawnIfColliding;
	AP_Bullet* NewBullet = GetWorld()->SpawnActor<AP_Bullet>(BasicBullet, PlayerShootArrow->GetComponentTransform(), SpawnParams);
	//AP_Bullet* NewBullet = GetWorld()->SpawnActor<AP_Bullet>(BasicBullet, PlayerShootArrow->GetComponentTransform());
	if (NewBullet) //  <-- CHECK IF THE BULLET EXISTS
	{
		NewBullet->Damage = this->Damage;
	}

I have this problem but in blueprints when spawning vehicles with physics or simple objects with physics… if you know solution, could you awnswer here?

https://answers.unrealengine.com/questions/879572/view.html

I believe it may be caused by the overlap event have for bullets:

void AP_Bullet::OnBeginOverlap(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	//If the overlapper is not null, is not itself, of other Comp is not a null pointer and is not of the same class.
	if (this)
	{
		if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr) && (!OtherActor->IsA(this->GetClass())))
		{
			if (!OtherActor->IsA(Shooter) && (OtherActor->GetClass()->ImplementsInterface(UI_DamageInterface::StaticClass()))) //Collision with anything that isn't what shot/can shoot the bullet
			{
				DealDamage(OtherActor);
			}
		}
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("This Does Not Exist Yet")));
	}
	
	
}

I will check back in if I find anything