How to save map in runtime?

when I add model to level in runtime,how to save the map?


If I’m understanding correctly, you want to be able to save a map after adding more actors to it during Play In Editor. There isn’t really an easy, built-in way to do this, as we typically expect anything that happens during PIE to revert once the session is stopped.

If you want to set up your own solution, I’d start by taking a look at EditorEngine. You’ll be able to find all of the functions we use internally to manage maps within the editor, so you may be able to trigger a save during your PIE session. Let me know if you have any specific questions and I’ll do my best to assist.



I want to be able to save a map after adding more actors to it during Play In Game without Editor. EditorEngine Module is not included in Game Mode.

Editor code is not permitted to be shipped as part of a game/project unless you have special licensing terms in your agreement with Epic. By default, that’s not the case.

Every level is also a package (via its outer) that contains all of the actors placed in it. So you can say Level->GetOuter()->SavePackage() to save that to disk. Every actor that is spawned as part of game play needs to have the level as its outer. By default, actors spawned at game runtime are spawned in the transient package which is expected to be for non-persistent objects.

SavePackage() is static function and not be used in game mode.Need I overwrite this function?

UPackage::SavePackage() is callable in game. It is not marked with WITH_EDITOR

bool UPackage::SavePackage(…)
if (FPlatformProperties::HasEditorOnlyData())
{ return false;}

There are
“if (FPlatformProperties::HasEditorOnlyData())” in UPackage::SavePackage(),so nothing code will be Executed

You’re right. Sorry about that . I didn’t look far enough into the code. You can try removing the cooked platform check, but there’s an unknown amount of work there