Question about calling scriptable object name

Hello, was looking to have a method in my scriptable object that will tell me the filename of my Scriptable object. That way when I have a scriptable object used I know which one was used so it won’t be again. From what I’m reading it may not be possible. I know I could create a string called name and name it manually in the inspector, but I’d like to reduce redundant work if possible.

Any ideas how I can accomplish this?

Thank you

I’m not sure what you mean. If you reference a scriptable object and call the name property, it returns the name of the file of that specific scriptable object. I’m doing this in a project right now.

You can do it with GetAssetPath:

private string myPath;

void OnValidate()
{
#if UNITY_EDITOR
    myPath = AssetDatabase.GetAssetPath(this);
#endif
}

Hold that thought. Because … what if you were to rename the asset? :wink:

Rather than creating one SO asset per use, create a single SO that contains a list of data that you want to use, and then keep the index of the data around wherever you need it. Similar problem by adding new items in between or deleting them though.