FString UHUDBlueprintLibrary::GetCurrentLevelName(UObject* WorldContextObject)
{
	UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
	FString MapName = World->GetMapName();
	FString MapPrefix = World->StreamingLevelsPrefix;
	MapName.ReplaceInline(*MapPrefix, TEXT(""));
	return MapName;
}
示例#2
0
void UGameInstance::StartRecordingReplay(const FString& Name, const FString& FriendlyName)
{
	if ( FParse::Param( FCommandLine::Get(),TEXT( "NOREPLAYS" ) ) )
	{
		UE_LOG( LogDemo, Warning, TEXT( "UGameInstance::StartRecordingReplay: Rejected due to -noreplays option" ) );
		return;
	}

	UWorld* CurrentWorld = GetWorld();

	if ( CurrentWorld == nullptr )
	{
		UE_LOG( LogDemo, Warning, TEXT( "UGameInstance::StartRecordingReplay: GetWorld() is null" ) );
		return;
	}

	FURL DemoURL;
	FString DemoName = Name;
	
	DemoName.ReplaceInline( TEXT( "%m" ), *CurrentWorld->GetMapName() );

	// replace the current URL's map with a demo extension
	DemoURL.Map = DemoName;
	DemoURL.AddOption( *FString::Printf( TEXT( "DemoFriendlyName=%s" ), *FriendlyName ) );

	CurrentWorld->DestroyDemoNetDriver();

	const FName NAME_DemoNetDriver( TEXT( "DemoNetDriver" ) );

	if ( !GEngine->CreateNamedNetDriver( CurrentWorld, NAME_DemoNetDriver, NAME_DemoNetDriver ) )
	{
		UE_LOG( LogDemo, Warning, TEXT( "RecordReplay: failed to create demo net driver!" ) );
		return;
	}

	CurrentWorld->DemoNetDriver = Cast< UDemoNetDriver >( GEngine->FindNamedNetDriver( CurrentWorld, NAME_DemoNetDriver ) );

	check( CurrentWorld->DemoNetDriver != NULL );

	CurrentWorld->DemoNetDriver->SetWorld( CurrentWorld );

	FString Error;

	if ( !CurrentWorld->DemoNetDriver->InitListen( CurrentWorld, DemoURL, false, Error ) )
	{
		UE_LOG( LogDemo, Warning, TEXT( "Demo recording failed: %s" ), *Error );
		CurrentWorld->DemoNetDriver = NULL;
	}
	else
	{
		UE_LOG(LogDemo, Log, TEXT( "Num Network Actors: %i" ), CurrentWorld->NetworkActors.Num() );
	}
}
示例#3
0
void FVisualLogger::SetIsRecordingToFile(bool InIsRecording)
{
	if (!bIsRecording && InIsRecording)
	{
		SetIsRecording(true);
	}

	UWorld* World = GEngine ? GEngine->GetWorld() : nullptr;

	const FString BaseFileName = LogFileNameGetter.IsBound() ? LogFileNameGetter.Execute() : TEXT("VisualLog");
	const FString MapName = World ? World->GetMapName() : TEXT("");

	FString OutputFileName = FString::Printf(TEXT("%s_%s"), *BaseFileName, *MapName);

	if (bIsRecordingToFile && !InIsRecording)
	{
		for (auto* Device : OutputDevices)
		{
			if (Device->HasFlags(EVisualLoggerDeviceFlags::CanSaveToFile))
			{
				Device->SetFileName(OutputFileName);
				Device->StopRecordingToFile(World ? World->TimeSeconds : StartRecordingToFileTime);
			}
		}
	}
	else if (!bIsRecordingToFile && InIsRecording)
	{
		StartRecordingToFileTime = World ? World->TimeSeconds : 0;
		for (auto* Device : OutputDevices)
		{
			if (Device->HasFlags(EVisualLoggerDeviceFlags::CanSaveToFile))
			{
				Device->StartRecordingToFile(StartRecordingToFileTime);
			}
		}
	}

	bIsRecordingToFile = InIsRecording;
}