UGameEngine::Experimental_ShouldPreDuplicateMap prevents begin play from running

When Experimental_ShouldPreDuplicateMap is set to true, like this:

bool UGameEngine::Experimental_ShouldPreDuplicateMap(const FName MapName) const
{
	return true;
}

This causes BeginPlay to be not be called on any actor, in the DynamicSourceLevel or DynamicDuplicateLevel

I built the engine from source, to try to find the cause, this didn’t happen in 5.3, I only noticed it in 5.5 and 5.6.

I started put break points in

bool UEngine::LoadMap( FWorldContext& WorldContext, FURL URL, class UPendingNetGame* Pending, FString& Error )

And stepped through the engine, which lead me here:

void AWorldSettings::NotifyBeginPlay()
{
	UWorld* World = GetWorld();
	if (!World->GetBegunPlay())
	{
		World->OnWorldPreBeginPlay.Broadcast();

		for (FActorIterator It(World); It; ++It)
		{
			SCOPE_CYCLE_COUNTER(STAT_ActorBeginPlay);
			const bool bFromLevelLoad = true;
			It->DispatchBeginPlay(bFromLevelLoad);
		}

		World->SetBegunPlay(true);
	}
}

For some reason, the ActorIterator for the world seems to be empty, causing no actor to have their BeginPlay function called.

Is this an engine bug, or is there something I might be missing?

Turns out in ue5 5.5 and up

You need to set

[ConsoleVariables]
s.World.CreateStaticLevelCollection=1

in

DefaultEngine.ini

1 Like