UE5.4.3 录屏回放系统ReplaySystem蓝图版

这是ReplaySystem的蓝图使用方法版,以第三人称模版为例,需要几个必须步骤

项目config内DefaultEngine.ini的最后添加:

[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="DemoNetDriver",DriverClassName="/Script/Engine.DemoNetDriver",DriverClassNameFallback="/Script/Engine.DemoNetDriver")

项目的.build.cs用添加Josn模块

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput","Json" });

创建MyGameInstance继承至GameInstance

MyGameInstance.h

// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "Engine/GameInstance.h"#include "NetworkReplayStreaming.h"
#include "Runtime/NetworkReplayStreaming/NullNetworkReplayStreaming/Public/NullNetworkReplayStreaming.h"
#include "Misc/NetworkVersion.h"#include "MyGameInstance.generated.h"USTRUCT(BlueprintType)
struct FS_ReplayInfo
{GENERATED_USTRUCT_BODY()UPROPERTY(BlueprintReadOnly)FString ReplayName;UPROPERTY(BlueprintReadOnly)FString FriendlyName;UPROPERTY(BlueprintReadOnly)FDateTime Timestamp;UPROPERTY(BlueprintReadOnly)int32 LengthInMS;UPROPERTY(BlueprintReadOnly)bool bIsValid;FS_ReplayInfo(){ReplayName = "Replay";FriendlyName = "Replay";Timestamp = FDateTime::MinValue();LengthInMS = 0;bIsValid = false;}FS_ReplayInfo(FString NewName, FString NewFriendlyName, FDateTime NewTimestamp, int32 NewLengthInMS){ReplayName = NewName;FriendlyName = NewFriendlyName;Timestamp = NewTimestamp;LengthInMS = NewLengthInMS;bIsValid = true;}
};UCLASS()
class REPLAYUE54_API UMyGameInstance : public UGameInstance
{GENERATED_BODY()public:UFUNCTION(BlueprintCallable, Category = "Replays")void StartRecordingReplayFromBP(FString ReplayName, FString FriendlyName);UFUNCTION(BlueprintCallable, Category = "Replays")void StopRecordingReplayFromBP();UFUNCTION(BlueprintCallable, Category = "Replays")void PlayReplayFromBP(FString ReplayName);UFUNCTION(BlueprintCallable, Category = "Replays")void FindReplays();UFUNCTION(BlueprintCallable, Category = "Replays")void RenameReplay(const FString& ReplayName, const FString& NewFriendlyReplayName);UFUNCTION(BlueprintCallable, Category = "Replays")void DeleteReplay(const FString& ReplayName);virtual void Init() override;TSharedPtr<INetworkReplayStreamer> EnumerateStreamsPtr;FEnumerateStreamsCallback OnEnumerateStreamsCompleteDelegate1;void OnEnumerateStreamsComplete1(const FEnumerateStreamsResult& Result);FDeleteFinishedStreamCallback OnDeleteFinishedStreamCompleteDelegate1;void OnDeleteFinishedStreamComplete1(const FDeleteFinishedStreamResult& Result);UFUNCTION(BlueprintImplementableEvent, Category = "Replays")void BP_OnFindReplaysComplete1(const TArray<FS_ReplayInfo>& AllReplaysm);	};

MyGmaeInstance.cpp

// Fill out your copyright notice in the Description page of Project Settings.#include "MyGameInstance.h"#include "Modules/ModuleManager.h"
#include "Runtime/Core/Public/HAL/FileManager.h"
#include "Runtime/Core/Public/Misc/FileHelper.h"void UMyGameInstance::Init()
{Super::Init();// create a ReplayStreamer for FindReplays() and DeleteReplay(..)EnumerateStreamsPtr = FNetworkReplayStreaming::Get().GetFactory().CreateReplayStreamer();// Link FindReplays() delegate to functionOnEnumerateStreamsCompleteDelegate1 = FEnumerateStreamsCallback::CreateUObject(this, &UMyGameInstance::OnEnumerateStreamsComplete1);// Link DeleteReplay() delegate to functionOnDeleteFinishedStreamCompleteDelegate1 = FDeleteFinishedStreamCallback::CreateUObject(this, &UMyGameInstance::OnDeleteFinishedStreamComplete1);
}
void UMyGameInstance::StartRecordingReplayFromBP(FString ReplayName, FString FriendlyName)
{StartRecordingReplay(ReplayName, FriendlyName);
}void UMyGameInstance::StopRecordingReplayFromBP()
{StopRecordingReplay();
}void UMyGameInstance::PlayReplayFromBP(FString ReplayName)
{PlayReplay(ReplayName);
}
void UMyGameInstance::FindReplays()
{if (EnumerateStreamsPtr.Get()){EnumerateStreamsPtr.Get()->EnumerateStreams(FNetworkReplayVersion(), int32(), FString(), TArray<FString>(), OnEnumerateStreamsCompleteDelegate1);}
}void UMyGameInstance::OnEnumerateStreamsComplete1(const FEnumerateStreamsResult& Result)
{TArray<FS_ReplayInfo> AllReplays;for (FNetworkReplayStreamInfo StreamInfo : Result.FoundStreams){void BP_OnFindReplaysComplete1(const TArray<FS_ReplayInfo> &AllReplaysm);if (!StreamInfo.bIsLive){AllReplays.Add(FS_ReplayInfo(StreamInfo.Name, StreamInfo.FriendlyName, StreamInfo.Timestamp, StreamInfo.LengthInMS));}}BP_OnFindReplaysComplete1(AllReplays);
}void UMyGameInstance::RenameReplay(const FString& ReplayName, const FString& NewFriendlyReplayName)
{// Get File InfoFNullReplayInfo Info;const FString DemoPath = FPaths::Combine(*FPaths::ProjectSavedDir(), TEXT("Demos/"));const FString StreamDirectory = FPaths::Combine(*DemoPath, *ReplayName);const FString StreamFullBaseFilename = FPaths::Combine(*StreamDirectory, *ReplayName);const FString InfoFilename = StreamFullBaseFilename + TEXT(".replayinfo");TUniquePtr<FArchive> InfoFileArchive(IFileManager::Get().CreateFileReader(*InfoFilename));if (InfoFileArchive.IsValid() && InfoFileArchive->TotalSize() != 0){FString JsonString;*InfoFileArchive << JsonString;Info.FromJson(JsonString);Info.bIsValid = true;InfoFileArchive->Close();}// Set FriendlyNameInfo.FriendlyName = NewFriendlyReplayName;// Write File InfoTUniquePtr<FArchive> ReplayInfoFileAr(IFileManager::Get().CreateFileWriter(*InfoFilename));if (ReplayInfoFileAr.IsValid()){FString JsonString = Info.ToJson();*ReplayInfoFileAr << JsonString;ReplayInfoFileAr->Close();}
}
void UMyGameInstance::DeleteReplay(const FString& ReplayName)
{if (EnumerateStreamsPtr.Get()){EnumerateStreamsPtr.Get()->DeleteFinishedStream(ReplayName, OnDeleteFinishedStreamCompleteDelegate1);}
}void UMyGameInstance::OnDeleteFinishedStreamComplete1(const FDeleteFinishedStreamResult& Result)
{FindReplays();
}

创建ReplayControllerplayer类继承至PlayerController类

ReplayControllerplayer.h
// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "ReplayControllerplayer.generated.h"/*** */
UCLASS()
class REPLAYUE54_API AReplayControllerplayer : public APlayerController
{GENERATED_BODY()public:/** we must set some Pause-Behavior values in the ctor */AReplayControllerplayer(const FObjectInitializer& ObjectInitializer);protected:/** for saving Anti-Aliasing and Motion-Blur settings during Pause State */int32 PreviousAASetting;int32 PreviousMBSetting;public:/** Set the Paused State of the Running Replay to bDoPause. Return new Pause State */UFUNCTION(BlueprintCallable, Category = "CurrentReplay")bool SetCurrentReplayPausedState(bool bDoPause);/** Gets the Max Number of Seconds that were recorded in the current Replay */UFUNCTION(BlueprintCallable, Category = "CurrentReplay")int32 GetCurrentReplayTotalTimeInSeconds() const;/** Gets the Second we are currently watching in the Replay */UFUNCTION(BlueprintCallable, Category = "CurrentReplay")int32 GetCurrentReplayCurrentTimeInSeconds() const;/** Jumps to the specified Second in the Replay we are watching */UFUNCTION(BlueprintCallable, Category = "CurrentReplay")void SetCurrentReplayTimeToSeconds(int32 Seconds);/** Changes the PlayRate of the Replay we are watching, enabling FastForward or SlowMotion */UFUNCTION(BlueprintCallable, Category = "CurrentReplay")void SetCurrentReplayPlayRate(float PlayRate = 1.f);
};

ReplayControllerplayer.cpp

// Fill out your copyright notice in the Description page of Project Settings.#include "ReplayControllerplayer.h"
#include "Engine/World.h"
#include "Engine/DemoNetDriver.h"AReplayControllerplayer::AReplayControllerplayer(const FObjectInitializer& ObjectInitializer)
{bShowMouseCursor = true;PrimaryActorTick.bTickEvenWhenPaused = true;bShouldPerformFullTickWhenPaused = true;
}bool AReplayControllerplayer::SetCurrentReplayPausedState(bool bDoPause)
{AWorldSettings* WorldSettings = GetWorldSettings();// Set MotionBlur off and Anti Aliasing to FXAA in order to bypass the pause-bug of bothstatic const auto CVarAA = IConsoleManager::Get().FindConsoleVariable(TEXT("r.DefaultFeature.AntiAliasing"));static const auto CVarMB = IConsoleManager::Get().FindConsoleVariable(TEXT("r.DefaultFeature.MotionBlur"));if (bDoPause){PreviousAASetting = CVarAA->GetInt();PreviousMBSetting = CVarMB->GetInt();// Set MotionBlur to OFF, Anti-Aliasing to FXAACVarAA->Set(1);CVarMB->Set(0);WorldSettings->SetPauserPlayerState(PlayerState);return true;}// Rest MotionBlur and AACVarAA->Set(PreviousAASetting);CVarMB->Set(PreviousMBSetting);WorldSettings->SetPauserPlayerState(NULL);return false;
}int32 AReplayControllerplayer::GetCurrentReplayTotalTimeInSeconds() const
{if (GetWorld()){if (UDemoNetDriver* DemoNetDriver = GetWorld()->GetDemoNetDriver()){return DemoNetDriver->GetDemoTotalTime();}}return 0;
}int32 AReplayControllerplayer::GetCurrentReplayCurrentTimeInSeconds() const
{if (GetWorld()){if (UDemoNetDriver* DemoNetDriver = GetWorld()->GetDemoNetDriver()){return DemoNetDriver->GetDemoCurrentTime();}}return 0;
}void AReplayControllerplayer::SetCurrentReplayTimeToSeconds(int32 Seconds)
{if (GetWorld()){if (UDemoNetDriver* DemoNetDriver = GetWorld()->GetDemoNetDriver()){DemoNetDriver->GotoTimeInSeconds(Seconds);}}
}void AReplayControllerplayer::SetCurrentReplayPlayRate(float PlayRate)
{if (GetWorld()){if (UDemoNetDriver* DemoNetDriver = GetWorld()->GetDemoNetDriver()){GetWorld()->GetWorldSettings()->DemoPlayTimeDilation = PlayRate;}}
}

创建MyGmaeInstance与ReplayController的BP蓝图类

UserInterface类:ReplayChild,ReplayMenu,ReplaySpectator

项目设置中

BP_MyGameInstance

 BP_ReplayController

 BP_ThirdPersonGameMode中的设置

 ReplayChild

ReplayMenu 

 

 

 ReplaySpectator

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/438716.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

二、Spring Boot集成Spring Security之实现原理

Spring Boot集成Spring Security之实现原理 一、Spring Security实现原理概要介绍二、使用WebSecurityConfiguration向Spring容器中注册FilterChainProxy类型的对象springSecurityFilterChain1、未配置securityFilterChain过滤器链时使用默认配置用于生成默认securityFilterCha…

JDBC 快速入门

JDBC 快速入门 搭建步骤代码实现数据库java 代码 搭建步骤 准备数据库官网下载数据库连接驱动jar 包。https://downloads.mysql.com/archives/c-j/创建 java 项目&#xff0c;在项目下创建 lib 文件夹&#xff0c;将下载的驱动 jar 包复制到文件夹里选中 lib 文件夹右键 ->…

第二十一章 (动态内存管理)

1. 为什么要有动态内存分配 2. malloc和free 3. calloc和realloc 4. 常⻅的动态内存的错误 5. 动态内存经典笔试题分析 6. 总结C/C中程序内存区域划分 1.为什么要有动态内存管理 我们目前已经掌握的内存开辟方式有 int main() {int num 0; //开辟4个字节int arr[10] …

【EXCEL数据处理】000009 案列 EXCEL单元格数字格式。文本型数字格式和常规型数字格式的区别

前言&#xff1a;哈喽&#xff0c;大家好&#xff0c;今天给大家分享一篇文章&#xff01;创作不易&#xff0c;如果能帮助到大家或者给大家一些灵感和启发&#xff0c;欢迎收藏关注哦 &#x1f495; 目录 【EXCEL数据处理】000009 案列 EXCEL单元格数字格式。文本型数字格式和…

CTK框架(十一):使用的常见问题

目录 1.MF文件路径 2.服务必须要接口类 3.插件名命名要求 4.生命周期问题 5.一个接口对多个实现注意 6.中文输出注意 7.同一插件安装注意 8.添加元数据 9.关于升级插件时遇到的问题 10.不同插件定义资源文件注意路径问题 11.安装插件 12.插件依赖 1.MF文件路径 在…

K8S:开源容器编排平台,助力高效稳定的容器化应用管理

云计算de小白 Kubernetes&#xff08;简称K8s&#xff09;是一个开源容器编排平台&#xff0c;用于自动化部署、扩展和管理容器化应用程序。 K8S诞生于Google&#xff0c;基于其多年在生产环境运行容器的经验&#xff0c;目前已成为现代微服务架构和云原生应用的核心技术。 图…

【C++算法】10.滑动窗口_长度最小的子数组

文章目录 题目链接&#xff1a;题目描述&#xff1a;解法C 算法代码&#xff1a;图解 题目链接&#xff1a; 209. 长度最小的子数组 题目描述&#xff1a; 解法 解法一&#xff1a;暴力求解&#xff08;会超时&#xff09; 暴力枚举出所有子数组的和。 查找子数组n2&#xff0…

云计算 Cloud Computing

文章目录 1、云计算2、背景3、云计算的特点4、云计算的类型&#xff1a;按提供的服务划分5、云计算的类型&#xff1a;按部署的形式划分 1、云计算 定义&#xff1a; 云计算是一种按使用量付费的模式&#xff0c;这种模式提供可用的、便捷的、按需的网络访问&#xff0c;进入可…

idea插件开发的第六天-开发一个笔记插件

介绍 Demo说明 本文基于maven项目开发,idea版本为2022.3以上,jdk为1.8本文在JTools插件之上进行开发本插件目标是做一款笔记插件,用于开发者在开发过程中随时记录信息仓库地址: jtools-notes JTools插件说明 Tools插件是一个Idea插件,此插件提供统一Spi规范,极大的降低了id…

微型导轨在IC制造设备的应用与优势

微型导轨的精度和稳定性对于机器的准确执行任务至关重要&#xff0c;其精确度通常用微米或毫米来衡量。其尺寸可以做到非常小&#xff0c;常运用在小型设备上&#xff0c;尤其是在IC制造设备中&#xff0c;其应用非常广泛。 在IC制造设备中主要用于半导体芯片的切割、封装和测试…

V2M2引擎源码BlueCodePXL源码完整版

V2M2引擎源码BlueCodePXL源码完整版 链接: https://pan.baidu.com/s/1ifcTHAxcbD2CyY7gDWRVzQ?pwdmt4g 提取码: mt4g 参考资料&#xff1a;BlueCodePXL源码完整版_1234FCOM专注游戏工具及源码例子分享

网站可疑问题

目标站点 Google hack 页面访问 抓包 POST /admin.php?actionlogin HTTP/2 Host: www.xjy.edu.cn Cookie: xkm_sidA6x4Cgw2zx User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0 Accept: text/html,application/xhtmlxml,appl…

使用 Light Chaser 进行大屏数据可视化

引言 在当今数据驱动的世界中&#xff0c;数据可视化变得越来越重要。Light Chaser 是一款基于 React 技术栈的大屏数据可视化设计工具&#xff0c;通过简单的拖拽操作&#xff0c;你可以快速生成漂亮、美观的数据可视化大屏和看板。本文将介绍如何使用 Light Chaser 进行数据…

Redis:string类型

Redis&#xff1a;string类型 string命令设置与读取SETGETMSETMGET 数字操作INCRINCRBYDECRDECRBYINCRBYFLOAT 字符串操作APPENDSTRLENGETRANGESETRANGE 内部编码intembstrraw 在Redis中&#xff0c;字符串string存储的是二进制&#xff0c;以byte为单位&#xff0c;输入的二进…

【HTML+CSS】留言板plus实现全过程

创建一个具有动态留言的简约风格留言板 在本教程中&#xff0c;我们将学习如何创建一个简约风格的留言板&#xff0c;它具备动态留言显示和一些基本动画效果。这个留言板将使用HTML和CSS构建&#xff0c;最终实现一个既美观又实用的界面。 准备工作 首先&#xff0c;确保你的…

面试速通宝典——7

150. 数据库连接池的作用 数据库连接池的作用包括以下几个方面&#xff1a; 资源重用&#xff1a;连接池允许多个客户端共享有限的数据库连接&#xff0c;减少频繁创建和销毁连接的开销&#xff0c;从而提高资源的利用率。 统一的连接管理&#xff1a;连接池集中管理数据库连…

Stream流的终结方法(一)

1.Stream流的终结方法 2.forEach 对于forEach方法&#xff0c;用来遍历stream流中的所有数据 package com.njau.d10_my_stream;import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.function.Consumer; import java.util…

Swagger配置且添加小锁(asp.net)(笔记)

此博客是基于 asp.net core web api(.net core3.1)框架进行操作的。 一、安装Swagger包 在 NuGet程序包管理中安装下面的两个包&#xff1a; swagger包&#xff1a;Swashbuckle.AspNetCore swagger包过滤器&#xff1a;Swashbuckle.AspNetCore.Filters 二、swagger注册 在…

戴尔PowerEdge R840服务器亮黄灯 不开机

最近接修到一台东莞用户的DELL PowerEdge R840 服务器因为意外断电后&#xff0c;无法正常开机的问题&#xff0c; 大概故障现象是 插上电源线 按卡机按钮无响应&#xff0c;无法开机&#xff0c;无显示输出&#xff0c;工程师到现场检修&#xff0c;经过idrac中日志分析&#…

K8S真正删除pod

假设k8s的某个命名空间如&#xff08;default&#xff09;有一个运行nginx 的pod&#xff0c;而这个pod是以kubectl run pod命令运行的 1.错误示范&#xff1a; kubectl delete pod nginx-2756690723-hllbp 结果显示这个pod 是删除了&#xff0c;但k8s很快自动创建新的pod,但是…