Guys do you know if there are any other setups i must do before spawning a actor in the Level? In my project there are various places that i spawn actors. But in this specific case, everytime this function is called my game Freezes and then crashes. I don’t have the slightest idea why. The code is almost the same in every place but in this class that it simply Crashes. Just to understand the class it is a Torpedo that when he explodes he spawns an explosion actor to deal damage. It so simple but it breaks the entire execution.
Please someone help me on this.
Code:
void ATorpedoTrap::Explode()
{
//Clear Any Timers
GetWorldTimerManager().ClearAllTimersForObject(this);
TorpedoUpdateTimeline.Stop();
//Check for a valid world
UWorld* const World = GetWorld();
if (World)
{
//Set the spawn parameters
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = Instigator;
// Get Actor Location to Spawn
FVector SpawnLocation = GetActorLocation();
//Set a rotation
FRotator SpawnRotation = GetActorRotation();
// Spawn the pickup
AActor* const SpawnedActor = World->SpawnActor<AActor>(Explosion, SpawnLocation, SpawnRotation, SpawnParams);
//Setup the Explosion params
AExplosion* Explosion = Cast<AExplosion>(SpawnedActor);
if (Explosion) {
Explosion->Setup(2.f);
}
}
if (!Destroy())
{
//Treat Powerup Failded destruction
UE_LOG(LogClass, Log, TEXT("Not able to destroy actor"));
}
}