Why does GEngine->GetWorld()->SpawnActor crash the engine?

I recently came across a rather annoying problem: spawning actors crashed my game with a memory access violation error. I double and triple checked everything, and it was all in order. After lots and lots of trial-and-error I accidentally discovered that (within a gamemode class) calling AActor::GetWorld()->SpawnActor succeeded while GEngine->GetWorld->SpawnActor failed. Seeing as GEngine isn’t null, I can’t justify this behavior in any way. Is there a specific reason, or is this a bug?

There can be multiple worlds active due to play in editor, etc. Use the actor version as it has the proper context and level info

Thanks for the info! I believe the failure could be more graceful than a memory access violation. I’ll take a look into the source to see where it’s happening.

GetWorld() can be null. That is where you are gettin ghte memory access violation.