Save skill tree

Hello, how are you?
I have a problem with my skill tree, in general it works very well, but I would very much like it to save both the skill points and the skills I already released, on the scene it saves, but when I close and open the game, everything is reset again, and I need to reap the points again, I’m new to unity could someone help me?

the code is in the link below
https://pastebin.com/VEt7eiiE

if you need more codes I try to save you can ask me to send
thanks for listening

Hi Marcos,

Welcome to our community! :slight_smile:

In which course and lecture are you?

Hi nina!
Thanks!

RPG Core Combat Creator: Learn Intermediate Unity C# Coding

I added a tag for you, so @Brian_Trotter can find your question more easily. :slight_smile:

Thanks!

First of all, well done on extending the RPG to include a skill tree! Our hopes are that more students will go beyond the basics and introduce new concepts of their own.

As the PlayerSkills is a base class, not derived from MonoBehavior, I’m not sure of the mechanism you’re using to reference it in the game.
I’m going to assume it’s created in a class like PlayerController and work my example from there… if it’s too different from this, we’ll get more information and work from there…

PlayerSkills playerSkills=new PlayerSkills();

PlayerController doesn’t implement the ISaveable interface, but this actually works well for us… we’ll implement ISaveable and add the CaptureState and RestoreState methods…

We’re also going to implement ISaveable in the PlayerSkills class…

[System.Serializeable]
public struct SkillSavingStruct
{
    public List<SkillType> skillList;
    public int skillPoints;
}

public object CaptureState()
{
     SkillSavingStruct savingStruct = new SkillSavingStruct();
     savingStruct.skillList = unlockedSkillTypeList;
     savingStruct.skillPoints = skillPoints;
    return savingStruct;
}

public void RestoreState(object state)
{
     SkillSavingStruct savingStruct = (SkillSavingStruct)state;
     unlockedSkillTypeList = savingStruct.skillList;
    skillPoints = savingStruct.skillPoints;
}

You may also need to add [System.Serializeable] above the SkillType enum for this to work properly.

Then the CaptureState and RestoreState for PlayerController (or whatever class has the PlayerSkills object) is a simple passthrough:

public object CaptureState()
{
    return playerSkills.CaptureState();
}
public void RestoreState(object state)
{
     playerSkills.RestoreState(state);
}

Thank you very much!!! I will try immediately, if it works I will come back here to give feedback, I have been trying hard to get this skill tree saved for two weeks but I couldn’t, I think it will work out very well!

I tried but it gave this error, I found it kind of strange, I’m trying to solve it.

my player controller code just below:
https://pastebin.com/B6rj7VGz

the language error is normal

None of this looks familiar from the RPG course… My approach won’t work, we’ll need to go at it a different way… I’ll have a go at solving it, but it might not be till my next day off of work.

Ok no problems!