Is this doc page really going to save and load data :0
If yes, gosh it’s cool! If not, how to save and load in Flax C#?
Is this doc page really going to save and load data :0
If yes, gosh it’s cool! If not, how to save and load in Flax C#?
Hi @Uosci , do you mean saving and loading game progression? Like in most RPG games out there?
Yes!
I still didn’t tried this system in Flax yet. I wonder if the link doc has that to offer me
Okay, so I skimmed through documentations and also some tutorials on Unity (Brackeys, Unity Tech, etc.) to look for references. For now I think there will be 2 ways to do this:
GameplayGlobals
(according to the documentation, it is used for Editor-only, probably best for debugging or testing):using FlaxEngine;
public class PlayerPrefs : Script
{
public GameplayGlobals PlayerDataGlobal; // You can assign Gameplay Globals asset here
public void TempPersist(PlayerData playerData)
{
PlayerDataGlobal.SetValue("enemyKilled", playerData.enemyKilled);
}
public PlayerData Load()
{
var enemyKilled = PlayerDataGlobal.GetValue("enemyKilled");
return new PlayerData(enemnyKilled);
}
}
JsonSerializer
// PlayerData.cs
using FlaxEngine;
namespace Game
{
/// <summary>
/// PlayerData Script.
/// </summary>
public class PlayerData : ISerializable
{
public string playerName = "Hello";
public int health = 0;
}
}
Then you can save/load using the sample code below:
using FlaxEngine;
using FlaxEngine.Json;
using System.IO;
namespace Game
{
/// <summary>
/// SaveSystem Script.
/// </summary>
public class SaveSystem : Script
{
private static int buildVersion = 6339;
public static void Save(PlayerData playerData)
{
var bytes = JsonSerializer.SaveToBytes(playerData);
File.WriteAllBytes("save1.data", bytes); // This will be saved in your project root directory
}
public static PlayerData Load()
{
var bytes = File.ReadAllBytes("save1.data");
PlayerData playerData = new PlayerData();
JsonSerializer.LoadFromBytes(playerData, bytes, buildVersion);
return playerData;
}
}
}
Hope that help!
Ah beautiful man!!! Thanks for piecing the codes! I’ll really need it.
I dont supposed anyone’s willing to upload a tutorial showing how to go about saving and loading.cause im switching from Unity to flax 1.6 and Iv got no idea what im doing.I’d really appreciate it
I found a free script for unity that automatically serialized the data and saves it to .Json file.
I changed 5 lines of code and now it allows Flax to have a sort of playerprefs saving system,
it can save floats ,ints ,strings ,vectors, and rotations.so it covers basically all of your variables.
it has no boolean’s bt in situations like that there are work arounds since all the basic variables are already covered,
For eg. Just create a Float or and Int when it = 1 it means true, 0 means false
I’d like to share it with the community but I don’t really know how.And Tips Guys
If you want to sell :
Sharing for free:
or you could just use google drive or anything like that.
Pls YouTube search Bobsi Save and Load Unity.It was Originally A Unity System but has been tweeked to work the same way in Flax engine.
U Could Create a new C# script in Flax Engine Then Copy And Paste the Code.
Or u Could do what i do,Which is to just have a ready made script and import that to Flax’s Source Folder"I use windows so i had to import it through file explorer"
I Hope this helps cause i only have flax for 3 days and i really love is but almost ended up leaving cause I Could not Understand the save and load functionality.Hope nobody else ends up feeling this way anymore cause saving and loading are vital to Game Creation
Type in 0 in the price to download the ready made script.
Just Extract and import.The TextFile links a video showing is usage in Unity but it works the same in Flax
I thought this example is for accessing separately generated(generating) .flax asset file to use in script driven apis, after cooking main game itself.
You can read/write any files without converting it to .flax format. Just use .Net.
I wanna see Flax Asset Store up. I may share some things. Like Save and Load.
You can also use the C# StreamReader and StreamWriter Classes to save and load data to/from a text file. So anyone can create their own save/load system. Or make a game super modable by loading data from some files at start and assigning the data to variables in game. Like weapon damage values, npc health values, all sorts of things. But you’d have to create your own system from scratch. The built in JsonSerializer is nice. I like the devs of this engine.
Yes, the engine is good, although there are still a few things missing and some bugs. There is also only a single developer actively working on the engine.
Does that mean this engine is on it’s way out?
Oh no, I think he’s been working on the engine since 2018 and has done incredible work. More and more features have been added and hardly a day goes by without updates. Flax is a really professional game engine and I think it will continue to be that way.
That’s great to hear because I love this engine.
The engine is simple and okay type for me. People trying to make small games can use Flax. But I want more advanced engine that does multiplayer and provides free high quality resources for solo devs like me. Quixel, PCG, Epic Online Services etc. On that case, you can choose UE5. I don’t mean Flax can’t do that but you’ll need to expand the engine yourself.
Biggest issue with UE5 is compilation time, there’s nothing much to do with the nature of C++.
I hope the engine will expand by time. To the guy developing the engine, I request a bigger workforce, specializing different areas of the engine. Rendering is high quality to be agreed!