How to temporarily store gameplay recording in game files

If anyone ever will find themselves facing the same situation, here is the answer:

  1. In your .h file create a struct for you replay info. It is needed to create a file and if you wish so, rename or delete it. It is saved in ProjectDir/Saved/Demos/.replayinfo
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(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;  
	}  
};
  1. In the same .h file create these variables and functions
public:

//ooking for/finding replays on hard drive 
UFUNCTION(BlueprintCallable, Category = Replays)  
void FindReplays(); 

virtual void Init() override;

private:

	//  helper function for FindReplays()   
	TSharedPtr<INetworkReplayStreamer> EnumerateStreamsPtr;  
	FOnEnumerateStreamsComplete OnEnumerateStreamsCompleteDelegate;  
    
	void OnEnumerateStreamsComplete(const TArray<FNetworkReplayStreamInfo>& StreamInfos);
  1. Define functionality and update/create Init(0
void UReplay::Init()
    {
    	Super::Init();
    
    	// create a ReplayStreamer for FindReplays() and DeleteReplay(..)
    	EnumerateStreamsPtr = FNetworkReplayStreaming::Get().GetFactory().CreateReplayStreamer();
    	// Link FindReplays() delegate to function
    	OnEnumerateStreamsCompleteDelegate = FOnEnumerateStreamsComplete::CreateUObject(this, &UReplay::OnEnumerateStreamsComplete);

    }

void UReplay::FindReplays()
{
	if (EnumerateStreamsPtr.Get())  
	{
		EnumerateStreamsPtr.Get()->EnumerateStreams(FNetworkReplayVersion(), 0, FString(), TArray<FString>(), FEnumerateStreamsCallback());// OnEnumerateStreamsCompleteDelegate was here, check if it's still needed
	}
}
  1. Create blueprint (can be any class really) and add following nodes

  1. Get yourself a nice cup of tea and keep going with a good work!
1 Like