Teleport system

Hi guys, I’m trying to create a teleport system between two different rooms which are defined by AROOM class. The problem is when the character goes on the teleport field(which is a box component), unreal closes itself without warnings or errors and I have to reopen the IDE. Code is written below

ARoom.cpp



ARoom::ARoom()
{
    ....]
        PassaggioTop->bGenerateOverlapEvents = true;
        PassaggioTop->OnComponentBeginOverlap.AddDynamic(this, &ARoom::PassaggioTopStart);
    ....]
}

void ARoom::PassaggioTopStart(class UPrimitiveComponent* newComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	APupetto* PersonagGiocante = Cast<APupetto>(OtherActor);
	if (PersonagGiocante != NULL) {
		FVector Destinazione = (RoomTop->PassaggioBottom->GetComponentLocation()) + FVector::FVector(0.0f, -100.0f, 0.0f);
		FRotator Rotazione = PersonagGiocante->GetActorRotation();
		PersonagGiocante->TeleportTo(Destinazione, Rotazione, false, false);
		//PersonagGiocante->SetActorLocation(Destinazione, false);
		//PersonagGiocante->SetActorRotation(Rotazione);
		this->Attiva = false;
		RoomTop->Attiva = true;
		RoomTop->AttivaCamera();
	}
}


ARoom.h



UFUNCTION(BlueprintCallable, Category = Teletrasporto)
		void PassaggioTopStart(class UPrimitiveComponent* newComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);



Try debugging through it, put a breakpoint for each line, and see on which one it crashes. Also look into all the variables to see if theres any null pointer or values you wouldnt expect. It’s pretty hard to investigate the code, because it is in - I assume - italian?

Make sure RoomTop is not NULL, and also PaddagioBottom and RoomTop. Also check if OtherActor is != NULL before the cast, not sure how UE4 handles NULL casting.



FVector Destinazione = (RoomTop->PassaggioBottom->GetComponentLocation()) + FVector::FVector(0.0f, -100.0f, 0.0f);


Likely the source of your problem. RoomTop and/or PassaggioBottom is probably NULL.

Casting NULL will fail. If a cast fails it returns a NULL pointer.