새소식

개발/UE4

[UE4] SaveGame 내 AActor 혹은 UObject 저장/불러오기 (스크랩)

  • -

언리얼 엔진의 USaveGame 객체는 1차적으로 본인만 시리얼라이즈 한 후 저장한다.
따라서 안에 들어가는 데이터가 시리얼라이즈 되어있는 데이터가 아니라면, Primitive한 타입들만 값이 보존된다.
이에 FArchive와 FArchiveProxy를 활용해 AActor나 UObject를 직렬화하고 관리하는 방법을 아래 두 사이트 링크를 통해 알 수 있다.

https://interstellarechidna.com/post/serializing-actors/

 

Serializing Monsters for Saving and Loading

At this point I have a bunch of data for monsters, resources, and plants. Now I need a way to dump all that into a file and read it in later so that the player can save and load their game. This is using the Unreal Engine, which has a class decriptively la

interstellarechidna.com

 

https://answers.unrealengine.com/questions/35618/savingloading-an-array-of-objects.html

 

What is the best way to handle Saving/Loading an Array of Objects? - UE4 AnswerHub

I've looked at tutorials, Tappy Chicken and Rama's example, but can someone tell me what is the "recommended" way to save and load an array of objects? More specifically, procedurally generated actors, which seem to break the FArchive derived routines in t

answers.unrealengine.com

간단하게는, UObject나 AActor의 Serialize 된 Binary Buffer을 담을 수 있는 UStrcut를 만든다.
UStruct 내부 프로퍼티 중 직렬화가 필요한 (메모리에 저장되어야 하는) 것은 'SaveGame' 메타 태그를 붙인다.
이렇게 만들어진 UStruct는 SaveGame의 프로퍼티로 관리되며, UGameplayStatics의 Save, Load 함수를 호출함으로써 
엔진 내 GeneralSaveSystem을 통해 파일 형태로 저장한다.

이 방법 중 UStruct을 Nesty하게 구성함으로써 모든 UActor와 UObject, Components를 손쉽게 저장하고 로드할 수 있게 된다.

다만 EasyMultiSave의 경우에는 살짝 다르다.
EMS는 Level, Player Archive에 대해서는 SaveGame 객체를 따로 생성하지 않는다. 대신 독자적으로 FArchive 를 구성하고 직렬화, 바이너리화를 거쳐 UE4에서 제공하는 파일시스템을 통해 저장한다.

덕분에 EMS는 중간과정에서 바이너리 데이터를 압축할 수 있어 기본적으로 USaveGame을 통해 구현한 파일보다 작은 용량으로 세이브를 관리할 수 있다.

대신 EMS의 멀티쓰레드를 활용한 저장 과정에서 유저의 메모리가 부족하거나 뭔가 장애가 생기면 쓰레드 프로세스 내에서 TimeManager나 World를 로드하지 못 해 게임 전체가 크래쉬가 터져 데이터를 손실시키는 일이 발생하기도 한다.

이에 현재 재직중인 회사에서는 EMS의 기본 구조에서 UE4의 세이브 시스템을 섞어 안전성있는 세이브 시스템을 구축하고 있다.

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.