Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

2
DestroyActor() causing crashes when reloading game
Post Body

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.

Author
Account Strength
100%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,894
Link Karma
5,368
Comment Karma
4,452
Profile updated: 3 days ago
Posts updated: 18 hours ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 months ago