Geometry script saving mesh at runtime

i can’t share screens sorry. as you might have noticed is not a obvious task, it took me a while to figure it out.

for loading it i resorted to ULevelStreamingDynamic::LoadLevelInstance(
you could also add them to the " Levels" panel window and use that with UGameplayStatics::LoadStreamLevel(World, LevelName . but loadlevelinstance will allow you to instantiate multiple of the same levels. it does comes with its own caveats (specially on unloading :frowning: )
i’ve managed to unload consistently by using UGameplayStatics::UnloadStreamLevelBySoftObjectPtr(GetWorld(), MyLevel

If you can get away with manually created levels, and using them only once. then i would recommend you to use the levels tab and the streamlevel system.
If you need to instance them, you should use LoadLeveInstance.

if you need to create the levels programmatically, you can use this.

the ONLY way i found for " saving" a new level was

  1. start with a template level
  2. duplicated it (that’s the only way i found)
    it will create a new object (unless you tell it to not overwrite). it will remain in memory until you literally " save it" (probably with the asset manager. i didnt needed/nor wanted to do this.)

you can check if the level already exists using the FAssetRegistryModule


UWorld* const WTemp = a TSoftObjectPtr<UWorld>.LoadSynchronous();
UWorld* const NewWorld = Cast<UWorld>(ObjectTools::DuplicateSingleObject(WTemp, PGN, ObjectsUserRefusedToFullyLoad, false, &Duplicated));
if (NewWorld)
{
	ULevel* const Level = NewWorld->GetCurrentLevel();
}

there are a lot of UWorld as you can tell. the “level” asset in ue afaik is handled via the world object. when you load an instance it’s like the level gets detached from its world and added to the parent one but the level needs to be contained in a world (or something like that im not sure).
this only work on editor. so you need to put it in a module that only runs on editor mode. (or use ifdefs which i don’t like much).

there are other things like landscapes and navmeshes which i only could properly serialize through adding them to this new level (as opposed to serialize regardless of any level).

I am using blueprints at the moment but I can jump to c++ if it is needed.

i wouldn’t think this is exposed to bps but haven’t really tried.

1 Like