I have two actors, the first one spawns actors with a method (spawn()) i’ve created, when i call this method from inside the actor (for example in Tick()), it works perfectly. The second one contains a boxcomponent triggering an action when overlapped by something. In my case when something gets into the zone, it calls the method spawn() from my first actor, but unreal freezes everytime and stay frozen forever (no crash report).
/*This method works fine when called from ASpawnActor*/
void ASpawnActor::spawn() {
if (whatToSpawn != NULL) {
UWorld* world = GetWorld();
if (world) {
FActorSpawnParameters params;
params.Owner = this;
params.bNoCollisionFail = true;
FVector loc = GetActorLocation()+offset;
FRotator rotation = FRotator::ZeroRotator;
rotation.Yaw = 90.f;
/*But crashe in the next line when called by ASpawnerTrigger::OverlapStart()*/
AActor *a=world->SpawnActor<AActor>(whatToSpawn, loc, rotation, params);
}
}
}
void ASpawnerTrigger::OverlapStart()
{
TArray<AActor*> ovAct;
TriggerBox->GetOverlappingActors(ovAct,ASpawnActor::StaticClass());
for (AActor* sa : ovAct) {
ASpawnActor* spawner = Cast<ASpawnActor>(sa);
if (spawner!=NULL) {
spawner->spawn();
}
}
}