Example #1
0
void UGameInstance::PlayReplay(const FString& Name)
{
	UWorld* CurrentWorld = GetWorld();

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

	CurrentWorld->DestroyDemoNetDriver();

	FURL DemoURL;
	UE_LOG( LogDemo, Log, TEXT( "PlayReplay: Attempting to play demo %s" ), *Name );

	DemoURL.Map = Name;

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

	if ( !GEngine->CreateNamedNetDriver( CurrentWorld, NAME_DemoNetDriver, NAME_DemoNetDriver ) )
	{
		UE_LOG(LogDemo, Warning, TEXT( "PlayReplay: 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->InitConnect( CurrentWorld, DemoURL, Error ) )
	{
		UE_LOG(LogDemo, Warning, TEXT( "Demo playback failed: %s" ), *Error );
		CurrentWorld->DestroyDemoNetDriver();
	}
	else
	{
		FCoreUObjectDelegates::PostDemoPlay.Broadcast();
	}
}
Example #2
0
void UGameInstance::StopRecordingReplay()
{
	UWorld* CurrentWorld = GetWorld();

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

	CurrentWorld->DestroyDemoNetDriver();
}
Example #3
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() );
	}
}