Hello! I am creating my 3d puzzle game and I need to store levels. I tried to use DataAsset, but I found it very uncomfortable to add new levels. I decided to use XML file to store them because it s quite simple to understand it and add a new level. I found XMLParser tutorials and understood them, but I can`t understand, how can I store this file in game package and access it from my game?
I will be also very pleased if you provide some information about other ways of storing data. Thanks in advance!
That’s a tough one
Now, I have never done this myself, and it seems like a big task, but I will try to help you anyway
If you want to do it the hard way, I think this is a good place to start looking
In …\Source\Editor\UnrealEd\Private\EditorServer.cpp
bool UEditorEngine::Map_Load(const TCHAR* Str, FOutputDevice& Ar)
{
// Line 2291 for version 4.8
...
{
//Load the map normally into a new package
const FName WorldPackageFName = FName(*LongTempFname);
UWorld::WorldTypePreLoadMap.FindOrAdd(WorldPackageFName) = EWorldType::Editor;
-> WorldPackage = LoadPackage( NULL, *LongTempFname, LoadFlags );
UWorld::WorldTypePreLoadMap.Remove(WorldPackageFName);
}
...
}
Slightly easier to create a class that loads the map on GameMode::BeginPlay or something:
#include "Engine/Level.h"
void AFoo::LoadMap(...)
{
// Start loading map here
}
void AFoo::SaveCurrentMap()
{
ULevel *Level = GetWorld()->GetCurrentLevel();
if (!Level)
return;
for (auto Actor : Level->Actors)
{
// Write XML
}
// Level also has other things that are worth saving i.e.
// ULevelScriptBlueprint* LevelScriptBlueprint;
}
1 Like
There’s a plugin which fully support XML read/write and table mapping, it can be used in both blueprints and c++. Tiny Xml Integration in Code Plugins - UE Marketplace