UE5.4.3 Replay 重播回放系统
工程的配置文件DefaultEngine.ini中需要加入
+NetDriverDefinitions=(DefName=“DemoNetDriver”,DriverClassName=“/Script/Engine.DemoNetDriver”,DriverClassNameFallback=“/Script/Engine.DemoNetDriver”)
此步骤将启用并加载DemoNetDriver
.ini添加示例
[/Script/EngineSettings.GameMapsSettings] GameDefaultMap=/Game/ThirdPerson/Maps/ThirdPersonMap.ThirdPersonMap EditorStartupMap=/Game/ThirdPerson/Maps/ThirdPersonMap.ThirdPersonMap
//新加部分
+NetDriverDefinitions=(DefName=“DemoNetDriver”,DriverClassName=“/Script/Engine.DemoNetDriver”,DriverClassNameFallback=“/Script/Engine.DemoNetDriver”)
关卡内所有staticmesh勾选static meshreplicate movement(确保actor被正确复制)
项目文件的build.cs中包含“Json”
创建一个自己的C++ GameInstance类
MyGameInstanceClass.h
// 在项目设置页面填写你的版权声明。
#pragma once
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "NetworkReplayStreaming.h"
#include "MyGameInstanceClass.generated.h"
// 定义一个结构体,用于存储回放信息
USTRUCT(BlueprintType)
struct FS_ReplayInfo
{
GENERATED_BODY()
UPROPERTY(BlueprintReadOnly)
FString ReplayName; // 回放文件名
UPROPERTY(BlueprintReadOnly)
FString FriendlyName; // 回放友好名称
UPROPERTY(BlueprintReadOnly)
FDateTime Timestamp; // 时间戳
UPROPERTY(BlueprintReadOnly)
int32 LengthInMS; // 回放时长(毫秒)
UPROPERTY(BlueprintReadOnly)
bool bIsValid; // 是否有效
// 构造函数,用于初始化回放信息
FS_ReplayInfo(FString NewName, FString NewFriendlyName, FDateTime NewTimestamp, int32 NewLengthInMS)
{
ReplayName = NewName;
FriendlyName = NewFriendlyName;
Timestamp = NewTimestamp;
LengthInMS = NewLengthInMS;
bIsValid = true;
}
// 默认构造函数
FS_ReplayInfo()
{
ReplayName = "Replay";
FriendlyName = "Replay";
Timestamp = FDateTime::MinValue();
LengthInMS = 0;
bIsValid = false;
}
};
// 定义一个游戏实例类,用于管理回放功能
UCLASS()
class REPLAYTEST_API UMyGameInstanceClass : public UGameInstance
{
GENERATED_BODY()
public:
// 初始化函数
virtual void Init() override;
private:
TSharedPtr<INetworkReplayStreamer> EnumerateStreamsPtr; // 回放流指针
FEnumerateStreamsCa