Unreal crash while Spawning actor c++

hi everyone, there is a problem that i couldn’t solve for days, HELP! i am trying to Spawn an Actor to the world and when i spawn the actor while game is running Unreal crashes. to be specific, i when my player overlaps a BoxComponent i want to spawn an Actor. let’s call it obstacle. here is the code for spawning.

void AObstacle::OnOverlapBegin(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	UE_LOG(LogTemp, Warning, TEXT("Overlapped"))

	SpawnLocation.X = this->GetActorLocation().X + 5000;
	SpawnLocation.Y = this->GetActorLocation().Y; 
	SpawnLocation.Z = this->GetActorLocation().Z;

	SpawnRotation = FRotator(0.f, 0.f, 0.f);

	if (ObstacleBP == NULL) { UE_LOG(LogTemp, Warning, TEXT("Obstacle is NULL")) return; }
	GetWorld()->SpawnActor<AObstacle>(ObstacleBP, SpawnLocation, SpawnRotation);

	this->SetLifeSpan(3.f);
}

i tried some similar thing before and i assume its becuz collision stuff. so here is a photo of Obstacle’s mesh and colliders.

here is where the obstacle should be Spawned(this is Floor which contains Some Collision to prevent the Player from falling.

thank you x_X.

Have you got the crash logs? That’ll help identify where the problem lies.

I guess it will spawn Actors like crazy when it overlaps. Try to add some check that this don’t happen.

Stack overflow - code c00000fd (first/second chance not available)

PhysX3PROFILE_x64!physx::Sq::AABBTreeOverlap::operator()() [d:\build++ue4\sync\engine\source\thirdparty\physx3\physx_3.4\source\scenequery\src\sqaabbtreequery.h:74]
PhysX3PROFILE_x64!physx::Sq::AABBPruner::overlap() [d:\build++ue4\sync\engine\source\thirdparty\physx3\physx_3.4\source\scenequery\src\sqaabbpruner.cpp:287]
PhysX3PROFILE_x64!physx::NpSceneQueries::multiQuery() [d:\build++ue4\sync\engine\source\thirdparty\physx3\physx_3.4\source\physx\src\npscenequeries.cpp:791]
PhysX3PROFILE_x64!physx::NpSceneQueries::overlap() [d:\build++ue4\sync\engine\source\thirdparty\physx3\physx_3.4\source\physx\src\npscenequeries.cpp:104]
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_RollerBall_587!AObstacle::OnOverlapBegin() [d:\unreaal projects\rollerball\source\rollerball\obstacle.cpp:65]
UE4Editor_RollerBall_587!AObstacle::execOnOverlapBegin() [d:\unreaal projects\rollerball\source\rollerball\obstacle.h:12]
UE4Editor_CoreUObject
UE4Editor_CoreUObject

here is the error log which appears when editor crashs

by the word crazy, it means? do you know any way to solve this? i guess its ue4 bug

Try

if (Obstacle)
{
GetWorld()->SpawnActor(ObstacleBP, SpawnLocation, SpawnRotation);
}

Instead of just spawning it just for a good measure and if that still crashes then you know to look somewhere else.

Start your UE editor from LocalWindowsDebugger in your IDE to catch the exact thing that triggers your crash.

By crazy I believe he meant that you would be spawning obstacles constantly just popping around but the function is OnOverlapBegin so I think that’s ok since after the initial overlap it doesn’t fire again until you end the overlap and start it again.

And a tip - you can use if (!Obstacle) for a nicer looking code :slight_smile:

Coolzies. :slight_smile: mark it as answered to help others :slight_smile:

good to have in mind :slight_smile:

hey, thanks but i kinda figured the problem, as i said in main question, its all about collisions. (:

i am pretty sure that this crash does not relate on my code cuz i attached debugger to the editor and when ue4 crashes there is nothing to do with the code, debugger shows nothing wrong about codes. so i was thinking to change the collision setting. i set the collision of where the obstacle will spawn, and it works.

i literally have no idea why it happens and is it a bug or nah! but it works fine, if you have spawn actor problems, and ur sure there is nothing to do with yr code, without wasting seconds change the collision settings.
when my obstacle’s box component, overlapped by the floor’s box component, becuz of collision stuff of floor, box components of obstacle and floor cuzed the crash O_o

sure, thanks (: