I’m using the ScriptableSingleton for the first time (Unity - Scripting API: ScriptableSingleton<T0>)
I use it to create and store IDs for npcs and other stuff.
But when I use the Save() method, it throws the error: “ArgumentException: Path cannot be the empty string or all whitespace.”
What am I missing? I’m doing the same as in the example in the unity docs, there doesn’t seem to be a way to specify the path appart from using [FilePath()], which I do. So why do I get that error?
Full code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[FilePath("IDs.foo", FilePathAttribute.Location.ProjectFolder)]
public class ID : ScriptableSingleton<ID>
{
[SerializeField]
private List<bool> TrainerIDs; //keeps track of which IDs are in use
[SerializeField]
private List<bool> NPCIDs; //keeps track of which IDs are in use
private int GetID(ref List<bool> IDs)
{
if (IDs == null)
{
IDs = new List<bool>();
}
else
{
for (int i = 0; i < IDs.Count; i++)
{
if (!IDs[i])
{
IDs[i] = true;
return i;
}
}
}
IDs.Add(true);
Save(true);
Debug.Log("MySingleton state: " + JsonUtility.ToJson(this, true));
return IDs.Count - 1;
}
public int GetTrainerID()
{
return GetID(ref TrainerIDs);
}
public void RemoveTrainerID(int iD)
{
TrainerIDs[iD] = false;
Save(true);
}
public int GetNPCID()
{
return GetID(ref NPCIDs);
}
public void RemoveNPCID(int iD)
{
NPCIDs[iD] = false;
Save(true);
}
}