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"

Serialization of default-constructed members?

Premise: I have been writing a saving system that relies on the SaveGame flag and the FArchive class hierarchy. So far I can save any actor in my world and restore it. However, it seems like when serializing an actor that has a member that is still default-initialized and has the SaveGame flag enabled, it will NOT get serialized.

Question: Why do default-constructed members with the SaveGame flag not get serialized when calling serialize on an actor? Also, how can I change that?

Context/Problem: Upon trying to load all actors in a level without opening the level again (simply search for every actor's save-entry and restore his data), I have encountered that default-initialized members of an actor or his components, do NOT get serialized.

So if my health default value is 100, I then save my actor, then get damaged to 75 health, then load that actor again, he remains at 75 health. Other values work correctly though. If I get damaged to health 75 first, then save, then get damaged to 50, then load, my health gets restored to 75 though.

This is not a problem when actually opening the level first, as a) values get stored when changed from default and b) values get default-initialized when the level gets opened. So, when loading a level anew, there is no problem. That's why I have taken so long to encounter this problem, as I only encountered it when trying to implement quick save and quick load, which does not make use of re-opening a level.

I have been debugging and logging my code a lot, so errors on my part seem to be non-existant in this case (95% sure).

Product Version: UE 4.18
more ▼

asked Feb 25 '18 at 01:19 PM in C++ Programming

avatar image

89 6 12 17

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

1 answer: sort voted first

I have done some digging in the engine code, and it became apparent that a property, should it pass the "ShouldSerializeValue" check from Class.cpp, still doesn't get serialized if the property in question has default values.

However, in the same check that refuses the default-initialized properties, the FArchive flag "ArNoDelta" gets checked too. So if you set the ArNoDelta flag of your FArchive (Proxy Archive in this case) to "true", then the property will pass the check regardless of its default-values.

The documentation/comment of ArNoDelta is wrong, as it is just copy pasted from the property directly above it. I am not entirely sure if setting that flag to true will result in other changes as well, but for now, setting it to true circumvents this 2nd check and allows for default-values to be saved.

more ▼

answered Feb 25 '18 at 04:57 PM

avatar image

89 6 12 17

(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