SpawnActorFromClass source location

There is a node called “SpawnActorFromClass” in BP, where is the source code location?

I want to learn about the flow of spawn a actor, for example, spawn params, construct function, C++ function calls and so on.I found UK2Node_SpawnActorFromClass.cpp, but there is no exec flow in it.

I haven’t looked super closely at the code, but it seems that node expands into a combination of UGameplayStatics::BeginDeferredActorSpawnFromClass and UGameplayStatics::FinishSpawningActor. The first of these functions ultimately calls UWorld::SpawnActorDeferred whereas the second one is a simple wrapper around AActor::FinishSpawning. (The header is in Engine/Classes/Kismet/GameplayStatics.h, the source in Engine/Private/GameplayStatics.cpp.)

This “two-part spawning” process for Blueprints exists so that ExposeOnSpawn properties can be handled correctly, but in general the spawning process is somewhat subtle.

After reading the sources, I found that UK2Node_SpawnActorFromClass is a subclass of UK2Node, and it overrride virtual void ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph) override;. When we compile a BP, the editor call the void UK2Node_SpawnActorFromClass::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph), and there the function in UGameplayStatics are bound.

So the “SpawnActorFromClass” is a little different from other BP nodes. I didn’t find how the function are exposed to BP, but ExpandNode function is enough.