Rolly Docs

Keep each player's profile

Keep data of each local player that lives outside any playthrough, such as unlocks, total wins or a chosen title, in a file of its own that loads when the player joins.

Sheet
16 of 64
Rev
1.0.0
Updated
On this sheet

Set it up

  1. Make a Blueprint of Rolly Save Profile (Content Browser, Blueprint Class, All Classes).
  2. Add its variables and tick SaveGame on each one to keep.
  3. Pick it in Project Settings > Plugins > Rolly Save > Profiles > Profile Class.

A variable without SaveGame ticked is not saved: Compiler Results and Data Validation warn about it (UnsavedVariable), and about a profile class without any saved variable (NoSavedVariable).

Read and change a profile

  • Get Profile, with Player set to the player’s own controller (such as Get Owning Player in a widget), gives the profile once it is usable, with Status Succeeded. While it loads it gives None with Busy. Cast it to your Blueprint to read and set its variables.
  • Load Rolly Profile gives the profile when it is ready: at once when it loaded, after its load otherwise. Use it where a widget may open before the load ends. Success comes with Succeeded, or with Not Found for a new player, whose profile holds your Blueprint’s defaults.
  • On Profile Loaded on the Rolly Save Subsystem fires when a profile load ends, the one when a player joins included; Result’s Slot Name is the profile’s key.

Save it

  • Save Rolly Profile saves the player’s profile.
  • With Save Profiles with Game (Project Settings > Profiles, on by default), each save to storage on this machine also saves every local player’s profile, so progress survives a crash whenever the game saved. These saves do not fire On Save Finished; On Profile Saved fires for every profile save.

Removing a local player saves nothing: save the profile before the player leaves.

What a profile holds

Each local player has a file of its own, <File Prefix>_profile_player<N>_a and _b, where N is the player’s platform user index; in Play In Editor, a client’s ends in _pie1, _pie2 and so on, since every instance shares one save folder. The file holds:

  • your Profile Class instance;
  • the SaveGame variables of the player’s Local Player Subsystems and of the local player;
  • the run ledger of single-slot runs (see Play single-slot runs), also without a Profile Class.

Where the platform’s save system keeps each user’s saves apart, as consoles do, each player’s profile is stored with that user’s saves; on Windows, Mac and Linux all profiles share the save folder. A storage backend of your own keeps players apart by overriding URollySaveBackend::MakeUserBackend. Profiles work on clients: each machine keeps its own players’ profiles. Saves of the game record the first local player’s key in their metadata (slot info Profile Key), so a slot screen can show each profile its own saves; Get Rolly Profile Key gives a player’s key.

Let players make named profiles

Set Project Settings > Plugins > Rolly Save > Profiles > Profile Keys to Named when several people share a machine and each picks a profile by name, as in many PC and couch games. Each named profile is a profile file of its own, <File Prefix>_profile_profile_<8 hexadecimal digits>_a and _b, with the player’s name in its header. The digits are random, so profiles made on two machines never share a key.

  • A player who has picked no profile yet gets a new one named after New Profile Name (Player {Number} by default, {Number} the lowest number no profile’s name has; a name without {Number} repeats, and a made name is cut to 64 characters). Once Max Named Profiles (8 by default, 1 to 64) exist, When Profiles Are Full decides: Reuse Oldest Unused gives the player the profile saved longest ago that no local player uses, with its progress; Refuse leaves the player’s profile unloaded (Get Profile gives Invalid Input) until Use Rolly Profile gives it one.
  • The choice is remembered in the platform user’s own profile file (player<N>), so the same profile loads at the next start.
  • Local players get their profiles one at a time, in the order they joined, so player 1 gets the lowest number. A profile one player uses, switches to or is being given is never given to another.
  • A save or part save made while the first player’s profile is being found, as the game starts, waits for it and records its key, or the key of the profile Use Rolly Profile picks meanwhile; a flush writes it at once, without the key.
Node What it does
List Rolly Profiles The named profiles by name (by key where names are equal), read from the slot index without opening their files: each one’s Key, Display Name, Save Time and Used By Player (the local player’s index, -1 for none).
Create Rolly Profile Makes a profile of Name, 1 to 64 characters. Failure with Invalid Input at Max Named Profiles, or for a name that is empty or too long (NameTooLong).
Rename Rolly Profile Changes a profile’s name; its key and files stay. A profile a local player uses is saved with its new name at once, and keeps its old name when that save fails. Busy while a player switches to it.
Delete Rolly Profile Deletes a profile’s file; with Delete Saves, every slot whose save records its key first, and the profile only once they are all gone. Refused with Invalid Input while a local player uses it, switches to it or is given it.
Use Rolly Profile Loads the profile of Profile Key for the player of Player and remembers the choice. See below.

Every node but List Rolly Profiles fails with Invalid Input unless Profile Keys is Named. Rolly Save’s slot screen has a profiles panel built on these nodes (see Give players a slot screen).

Key profiles by account with a provider

Set Profile Keys to Provider when the platform signs players in to an account, such as a store or console account, and each account should keep its own profile on any machine. Your Player ID Provider gives each local player’s key as the player joins; the profile’s file is <File Prefix>_profile_id_<key>_a and _b, the key made safe for every file system as slot names are.

  • A key is any text of 1 to 1,024 characters. An empty key, or a longer one, gives the player the platform user’s profile instead, with a setup warning once (ProviderEmptyKey, ProviderKeyTooLong).
  • Rolly Save makes one provider per game instance as the game starts and asks it once per joining player; the provider’s class is always cooked.
  • With Profile Keys at Provider and no usable provider class, every player uses the platform user’s profile, with the setup error NoProvider; Data Validation reports it in the editor.
  • Named profile nodes, the profile chip and the profiles panel need Named keys; with Provider keys the slot screen lists the player’s profile’s saves (Slots Shown Auto).

Blueprint

  1. Make a Blueprint of Rolly Save Player ID Provider (Content Browser, Blueprint Class, All Classes).
  2. Override Get Profile Key: from its Local Player, return the account’s ID your online code keeps, such as the unique net ID as a string.
  3. Pick it in Project Settings > Plugins > Rolly Save > Profiles > Player ID Provider, with Profile Keys at Provider.

C++

#include "Profile/RollySavePlayerIdProvider.h"

UCLASS()
class UMyPlayerIdProvider : public URollySavePlayerIdProvider
{
	GENERATED_BODY()

	virtual FString GetProfileKey_Implementation(ULocalPlayer* LocalPlayer) const override
	{
		return LocalPlayer ? LocalPlayer->GetPreferredUniqueNetId().ToString() : FString();
	}
};
C++

Switch profile during play

Use Rolly Profile gives the player another named profile: the profile it had goes, unsaved, and the new one loads as a joining player’s does, so On Profile Loaded fires and Get Profile gives Busy until it ends. The SaveGame variables of the local player and its Local Player Subsystems go back to their class defaults first. Three things keep the old profile’s values when the new profile holds none for them: SaveGame variables inside instanced objects, data a class writes in its own Serialize, and state your game builds in On Rolly Save Loaded; reset those in On Profile Loaded. Call Save Rolly Profile first when the profile changed since its last save. Use Rolly Profile saves nothing by itself, works only with Profile Keys at Named, and is refused while another local player uses the profile or switches to it. A damaged platform user’s file is replaced by one that holds the choice. Called while the player’s profile is still being found as it joins, Use Rolly Profile ends that search: no profile is made for the player, and the one Use Rolly Profile picks is remembered.

Decide where runs record their saves

Single-slot runs record their newest save so an older copy cannot load (see Play single-slot runs). Project Settings > Plugins > Rolly Save > Profiles > Run Ledger decides where:

Run Ledger Records in Use it when
Profile (default) the first local player’s profile one profile per player, as with Platform User keys
Shared one file, <File Prefix>_profile_runledger, for every profile and a dedicated server players switch profiles (Named or Provider keys), or a dedicated server runs the game
Off nowhere runs need no protection; older copies load

With Profile, switching to another profile would let an older copy of a run load under it: Data Validation warns about Run Ledger at Profile while Profile Keys is Named or Provider (LedgerPerProfile). A shared file that cannot be read is never written over: runs then save without being recorded, as when no profile is loaded.

When a profile does not load

A profile that loads as Damaged, Newer Version, Migration Failed or Storage Failed stays unusable, and its file is never written over with defaults: Get Profile gives None with that status, Save Rolly Profile fails with it, and a setup warning names the profile once (Refused). Tell the player, then:

  • Load Rolly Profile reads the file again, such as after the storage came back;
  • Reset Rolly Profile deletes both copies and gives a profile of defaults, the player’s SaveGame variables included, written at the next save. Under Named keys, a player left without a profile gets one again, as a joining player does; the platform user’s file that names the player’s profile is deleted first only when it is Damaged, so a player refused by When Profiles Are Full, or whose file the storage could not read, keeps that file and the records it holds.

Profiles of a lower Game Data Version go through the Migrations asset as saves do (see Keep old saves loading after an update).

From C++

#include "Profile/RollySaveProfile.h"

ERollySaveStatus Status;
if (UMyProfile* Profile = Cast<UMyProfile>(Save->GetProfile(*LocalPlayer, Status)))
{
	Profile->Wins += 1;
	Save->SaveProfile(*LocalPlayer);
}
Save->LoadProfile(*LocalPlayer, [](const FRollySaveResult& Result, URollySaveProfile* Profile)
{
	// Profile is usable when Result succeeded or is NotFound (a new player).
});

// Named profile keys.
Save->ListProfiles([](const FRollySaveResult& Result, const TArray<FRollySaveProfileInfo>& Profiles) {});
Save->CreateProfile(TEXT("Anna"), [Save, PlayerController](const FRollySaveResult& Result, const FRollySaveProfileInfo& Made)
{
	Save->UseProfile(PlayerController, Made.Key, [](const FRollySaveResult& Used, const FRollySaveProfileInfo& Profile) {});
});
C++