Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

scriptable object guid unity

using UnityEngine;

public class SerializableScriptableObject : ScriptableObject
{
    [SerializeField] Guid _guid;
    public Guid Guid => _guid;

    void OnValidate()
    {
#if UNITY_EDITOR // UnityEditor namespace is not available in Release/Builds
        var path = UnityEditor.AssetDatabase.GetAssetPath(this);
        _guid = new Guid(UnityEditor.AssetDatabase.AssetPathToGUID(path));
#endif
    }
}
Source by bronsonzgeb.com #
 
PREVIOUS NEXT
Tagged: #scriptable #object #guid #unity
ADD COMMENT
Topic
Name
5+7 =