x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Using Save Game functionality with UObjects

I followed the documentation regarding Unreal's built-in support for save games. I subclassed USaveGame and added some pointers to UObject-derived classes to be serialized. e.g.

 class UDerivedSaveGame : public USaveGame
 {
     GENERATED_BODY()
  public:
     UPROPERTY()
     UDerivedClass* Data1;

 // more data

 };

However, it doesn't look like the data that Data1 points to is getting serialized. I have an array of FString's in one of my UObject-derived classes, and I'd expect to see those strings if I opened the save file with a hex editor.

I was just wondering how to serialize the UObject-derived classes that the pointers point to. I appreciate any insight anyone may have!

Product Version: UE 4.13
Tags:
more ▼

asked Nov 12 '16 at 04:34 AM in C++ Programming

avatar image

tginick
53 3 6 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

After a bit of digging into engine code, I think I solved the problem (at least for my use case)!

Subclass the existing FMemoryWriter class and override the following operator as follows...

 FArchive& FTraversingObjectWriter::operator<<(class UObject*& Res)
 {
     FString ClassName = Res->GetClass()->GetName();
     (*this) << ClassName;
 
     Res->Serialize(*this);

     return *this;
 }

FTraversingObjectWriter is the new class I wrote. This solution seems to work even if I reorder the properties in my class declaration. It also appears to work with arrays of UObject pointers.

I'll leave the implementation of the inverse operation as an exercise to the reader. One can go about this by doing the following...

  1. Read the ClassName string and find the UClass associated with that ClassName.

  2. After that, instantiate a new UObject with the UClass you found with NewObject

  3. Deserialize your object.

more ▼

answered Nov 12 '16 at 10:17 PM

avatar image

tginick
53 3 6 10

avatar image ColdSteel48 Mar 11 '18 at 02:22 AM

I am sorry but I don't get where and how to use this FMemoryWriter class

Or I just should to call it manually outside the SaveGame class ?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question