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"

UClass values invalid after saving and loading in packaged game?

I'm creating a saving and loading system by serializing data via the FArchive class hierarchy and it works just fine in the editor.

When packaging I have encountered corrupted data however. I'm storing an actor in the following struct:

 struct FActorRecord {
     UClass * ActorClass;
     FString ActorName;
     FTransform ActorTransform;
     TArray<uint8> ActorBinaries;
     TArray<FActorComponentRecord> ComponentData;
     FActorComponentRecord SaveComponent;
     bool bDestroyed = false;
     int32 recordIndex = -1;
     friend FArchive& operator<<(FArchive& Ar, FActorRecord& actorRecord)
         Ar << actorRecord.ActorClass;
         Ar << actorRecord.ActorName;
         Ar << actorRecord.ActorTransform;
         Ar << actorRecord.ActorBinaries;
         Ar << actorRecord.ComponentData;
         Ar << actorRecord.SaveComponent;
         Ar << actorRecord.bDestroyed;
         Ar << actorRecord.recordIndex;
         return Ar;

I assign the ActorClass value by using actor->GetClass() when storing an actor to records and in editor the value is always correct and works; in the packaged game, however, the value seems to be garbage sometimes. It can be "Invalid", it can be random classes of actors that I did not ever save etc. pp. As can be seen in the following image, the first and last entry in that array have wrong values.

alt text The ActorNames are correct and the class should be similar to the name. So the first record's class should be B_Villager_C (or similar), just like with all other entries in the array. SavingTrigger and LoadingTrigger are values that did not ever get written to this array in the first place. The engine seems to mix some things up in the packaged version of the game.

This results in the packaged game crashing when accessing the saving system, but only sometimes. I have found that saving and loading the entire game in the first start-up leads to a crash. However, when I start the game again, then load the save that I tried to load in the prior instance of the game, it works.

The entire saving system is in the GameInstance. The initial reading of the save game file is correct and the data entries in the save file indicate the correct classes, too. It's just that something gets written into the array at run-time, it looks like. The error also seems to exclusively exist in the UClass * ActorClass, as all other values of the FActorRecord seem to be correct entirely.

Product Version: UE 4.18
more ▼

asked Mar 16 '18 at 12:19 PM in C++ Programming

avatar image

79 5 10 17

avatar image Quexlaw Mar 18 '18 at 03:09 PM

Bump. More time of debugging; results: the UClass * change values and my code is not responsible. I have set it to watch the addresses of the UClass pointer fields and they simply change at one point or another, but only in the packaged game.

My guess is that is has to do with a) re-allocation or b) garbage collection. Maybe Unreal moves the UClass addresses at some time? I don't know.

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

0 answers: sort voted first
Be the first one to answer this question
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