How to save a character

Hi, I’m working in a mmorpg and I have a question:

I’ve created a scene where you can custom your character, activating/desactivating character’s children(such as hair, cloth, etc) you can custom it. The thing is that I want to save the character once it’s as you like and show it in the player’s profile as animated character.

I don’t know the command to do it, or if it’s possible to save activated/desactivated game objects inside oneother game object.

I don’t know if I made myself clear…

It’s probably best to save the choices as variable values; Once the player has selected the ones they want, pass the references to those objects to some controller object and have it hold on to the values. Any other object that needs them can then ask your controller which parts to use.

Did you try with save into JSON file format?

So what’s the command I must use to save the variable values?

I don’t know that format…

I thought of this:

SCRIPT TO SAVE:

public class CreatenewCharacter : MonoBehaviour {

public GameObject Corto;
private string activado;
private string desactivado;

void OnGUI () {

if (GUI.Button(new Rect(1220, 640, 70, 30), “Cear”))
{

if (Corto.activeSelf == true)
{
PlayerPrefs.SetString(“Pelo1”, activado);
}
if (Corto.activeSelf == false)
{
PlayerPrefs.SetString(“Pelo1”, desactivado);
}

SCRIPT TO GET WHAT I SAVED:

void Start()
{

PlayerPrefs.GetString(“Pelo1”);
if (string.Contains(activado))
{
Corto.SetActive(true);
}

}

But there is an error: it says that ‘’ if (string.Contains(activado)) ‘’ is wrong (An object refence is required). So how can I say ‘’ if the saved string with the key ‘‘Pelo1’’ is ‘‘Activado’’, then activate the gameobject called Corto’'?

Hi, try to initialise activado as string.
Sorry, why you don’t serialized Corto, rather than use the string ?

How do I do both? If I don’t see the script I don’ understand what you mean, sorry.

void Start()
{
activado = null;

PlayerPrefs.GetString(“Pelo1”);
if (string.Contains(activado))
{
Corto.SetActive(true);
}

}

about serialization, take a look to this: Unity - Manual: Script serialization

The issue is that you’re not comparing anything in

if (string.Contains(activado))

string isn’t an object or a variable. It’s a data type.

if (something.name.Contains(activado))

for example, would work because you’re looking at the string of something that contains a value and checking if it contains activado

OK

It works great!!!

Thankyou everyone for helping, you are awesome!

XOXOXO