How can I get the name or UniqueID of the Asset i am working on?

Hello toghether

Is it possible to get the Asset of the scriptableObject? I mean simlilar like this.gameObject in Monobehaviour?

Example:

public class scrObj : scriptableObject
{
private scrObj  _Asset;

void Main()
{
_Asset = this.?????

}

May be I got a solution with https://docs.unity3d.com/Packages/com.unity.addressables

Anybody experienced with? Does it work for my case?

@Patrick_Rainer

You need this in some editor thing like custom editor window? Or something else?

Yes, need it for a custom editor window and later for giving a reference to the asset in a instantiated gameobject while runtime.

Something like this?

// this instance asset path
var path = AssetDatabase.GetAssetPath(this.GetInstanceID());
Debug.Log("Asset path:" + path);

// Get asset with path
var asset = AssetDatabase.LoadAssetAtPath(path, typeof(ScriptableObject));
Debug.Log("Asset instance id:" + asset.GetInstanceID());

This would be in your scriptable object in this case.

Edit:

“and later for giving a reference to the asset in a instantiated gameobject while runtime.”

Although I don’t know about this part…

4 Likes

Man you are great. It works just fine! :wink:

SOLVED

@Patrick_Rainer

Then why not like my answer :wink: