This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
So I have code on my bullets that causes them to destroy themselves, and, if they are flagged as explosives, spawn an explosion as well. This code activates on contact with a wall, or after a designated amount of time (let's say 5 seconds). The code works fine for the most part, but whenever I reload the game by re-opening the current map, after about a few seconds the game will crash, with Visual Studio throwing an unhandled exception error at the end of my bullet destroy function. I assume it has something to do with my lifetime timer, which currently looks like this.
FTimerDelegate TimerDelegate;
TimerDelegate.BindLambda([&]
{
if (IsValid(this)) {
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 1, FColor::Green, FString("Time Up"));
BulletDestroy();
}
});
FTimerHandle TimerHandle;
GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDelegate, BulletLifetime, false);
Meanwhile the BulletDestroy() code looks like this
//Runs the code for destroying the bullet
void ANormalBullet::BulletDestroy() {
if (IsValid(this)) {
//If the bullet is explosive, spawn an explosion before destroyiung
if (IsExplosive) {
AExplosion* SpawnedExplosion = GetWorld()->SpawnActorDeferred<AExplosion>(ExplosionBP, GetActorTransform(), nullptr, nullptr, ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
//If the bullet was fired by an enemy, make the explosion deal damnage to the player
if (IsPlayerBullet) {
SpawnedExplosion->IsEnemyExplosion = false;
}
else {
SpawnedExplosion->IsEnemyExplosion = true;
}
UGameplayStatics::FinishSpawningActor(SpawnedExplosion, GetActorTransform());
}
AActor::Destroy();
}
return;
}
Is there some kind of null check I'm missing that could be causing the crash? Do I need to cancel the lifetime timer delegates when reloading the game? Any help would be very appreciated.
Subreddit
Post Details
- Posted
- 5 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/unrealengin...