Reference ID not found and KeyNotFoundException

Discussion and help for Easy Save 3
Post Reply
Coldwynn
Posts: 22
Joined: Sun Oct 30, 2022 11:56 am

Reference ID not found and KeyNotFoundException

Post by Coldwynn »

Hello,

I hope someone can help me understand what I'm doing wrong.

I have two scenes, in scene1, I define the default team name and logo - or, if the game has been run before, load the working team name and logo; then with a button click the user can switch to the a "work" scene (there are many such work scenes).

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using TMPro;


public class LoadDefaults : MonoBehaviour
{
    //gain access to team name and logo on scene
    //gain access to basic gameObjects
    public GameObject currentTeamName;      
    public GameObject currentTeamLogo;

    //define and get access to the string of currentTeam
    public string DefaultTeamName = "Erie Frostline";

    void Start()
    {
        //gain access to text component of TMP
        TextMeshProUGUI currentTeamName_UI = currentTeamName.GetComponent<TextMeshProUGUI>();

        if (ES3.KeyExists("activeTeam"))
        {
            //REassign the logo and collect teamName
            ES3.LoadInto<GameObject>("activeTeamLogo", currentTeamLogo);
            DefaultTeamName = ES3.Load<string>("activeTeamName");
        }

        //assign the teamName (whether stored or just assigned, the name and logo are the same)
        currentTeamName_UI.text = DefaultTeamName;

        //Note: at this point, currentTeamName_UI.text contains the teamName being worked on
        //and currentTeamLogo contains its logo
        //these should be saved in a scriptableobjects or ES3 file for later use
        ES3.Save<string>("actvieTeamName", currentTeamName_UI.text);
        ES3.Save<GameObject>("activeTeamLogo", currentTeamLogo);
        
        
    public void OnBClick()
    {
        SceneManager.LoadScene("OptionsMenu");
    }
    }
At the "OptionsMenu" scene, the current team name and logo are reloaded/updated as follows:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using TMPro;

public class teamHQ : MonoBehaviour
{
    public GameObject CurrentTeamLogo;
    public GameObject CurrentTeamName;

    void Start()                                                                                                                                                                                                                                                                                                                                                                    
    {
        ES3.LoadInto<GameObject>("activeTeamLogo", CurrentTeamLogo);
        TextMeshProUGUI CurrentTeamName_UI = CurrentTeamName.GetComponent<TextMeshProUGUI>();
        ES3.LoadInto<string>("activeTeamName", CurrentTeamName_UI.text);
    }
But Ii get the following warning and error:

Image

Thank you, in advance, for your time.
Attachments
Screen Shot 2022-11-04 at 8.38.58 AM.png
Screen Shot 2022-11-04 at 8.38.58 AM.png (213.09 KiB) Viewed 707 times
User avatar
Joel
Moodkie Staff
Posts: 4851
Joined: Wed Nov 07, 2012 10:32 pm

Re: Reference ID not found and KeyNotFoundException

Post by Joel »

Hi there,

There is a type in your code. You're saving to a key named "actvieTeamName", but you're trying to load from a key named "activeTeamName".

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Coldwynn
Posts: 22
Joined: Sun Oct 30, 2022 11:56 am

Re: Reference ID not found and KeyNotFoundException

Post by Coldwynn »

Oh my g..., that was embarrassing. Sorry about that.

However, when I fixed the offending typo, and run it, I still get this:

Image
Attachments
Screen Shot 2022-11-04 at 12.45.58 PM.png
Screen Shot 2022-11-04 at 12.45.58 PM.png (213.46 KiB) Viewed 703 times
User avatar
Joel
Moodkie Staff
Posts: 4851
Joined: Wed Nov 07, 2012 10:32 pm

Re: Reference ID not found and KeyNotFoundException

Post by Joel »

Hi there,

This usually means that the type of a piece of data has changed, meaning the save data is no longer valid (for example, changing the type of a field from 'string' to 'GameObject'). In this case deleting the save data by going to Tools > Easy Save 3 > Clear Persistent Data Path should resolve the issue.

If you've created an ES3Type from the Types window for the type which has changed, you may also need to regenerate it.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply