How not to save a variable, but have it duplicated/persist when going into PIE mode ?

I have an array variable, contains a huge precomputed data. Saving it (not save game, but in editor with the map) fail because it’s more than 2GB in size. I tried NonPIEDuplicateTransient hoping that the data don’t get saved, but gets duplicated when going into PIE, so we can skip the precomputation part which is very time consuming. But even with NonPIEDuplicateTransient, the data is still saved, and because it’s over 2GB, saving just crash the editor.

Is this a bug ? because it seems wrong to “save” the data only to have it reset to default when loaded, or is there something I missed ?

Thank you!

If you want to avoid it being saved you want to mark it Transient.

Yes I’ve tried that, and yes setting it to Transient doesn’t save. But when I start a PIE session, the array variable doesn’t get duplicated either, it’s “Empty”, so I have to precompute everything again from scratch which is very time consuming (and it gets annoying real fast).

To rephrase my question, I need my variable to be duplicated for a PIE session, but not saved.

“NonPIEDuplicateTransient” duplicates, but it saves.
“Transient” doesn’t duplicate and doesn’t save either.

If there isn’t a way to do this, could you please say so ? That way we can find a different way to overcome this and keep moving forward.

I don’t think it’s possible to do what you’re suggesting. The PIE machinery uses the same machinery involved in saving games.

I think what you’ll have to do is create another system for managing this large amount of data. Instead of an array variable you would store some identifier that you can use to retrieve this information.

With a separate system you should be able to set it up in such a way that it is preserved for PIE but ignored for serialization.

Edit: On second thought, I’m sure there is some way in PIE mode to locate the other world context that you originally generated the data in. Perhaps then you could override PostLoad() to detect PIE mode, look up the original actor, and reference the same data.

I actually did take a look, but there is no property flag to allow this. The reasoning is that we want PIE to be as accurate a representation of playing the game as possible, though a few shortcuts are taken to make it start as fast as possible (for example using duplication instead of saving to disk and reloading).

If you were to use instead of a UPROPERTY native serialization (overriding the ::Serialize function), you might be able to accomplish this with something like (and I haven’t tested this, but it might point you in the right direction).



void AMyClass::Serialize(FArchive& Ar)
{
   Super::Serialize(Ar);

   if (Ar.GetPortFlags() & PPF_DuplicateForPIE)
   {
      Ar << MyGiantArray;
   }
}


You can see an example of something like this in Landscape.cpp that was done for the open world demo. (https://github.com/EpicGames/UnrealEngine/blob/master/Engine/Source/Runtime/Landscape/Private/Landscape.cpp)

Marc, that works wonderfully!
Thank you very much!