I have my class Save which contains some variables. I want to save it like an asset to be able to load it later. The save is good (I check the content in mode force text), but when I try to load my Asset with Ressources.Load(), this function return null.
Here is my code :
public void LoadAsset()
{
UnityEngine.Object data;
data = Resources.Load(assetPathAndName);
//assetPathandName = "Assets/New Save 33.asset"
Save tmp = (Save)data;
if (data == null)
Debug.Log("Data is null, LoadAsset has failed");
bool loaded = (data != null);
if(!loaded)
{
data = ScriptableObject.CreateInstance<Save>();
AssetDatabase.CreateAsset(data, assetPathAndName);
}
else
return;
AssetDatabase.SaveAssets();
}
I don’t understand why my data is null.