CodeSmile AssetDatabase 1.9
Unity's AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.
Loading...
Searching...
No Matches

◆ GetGuid()

static GUID GetGuid ( [NotNull] Object asset)
static

Returns the GUID of an object. Returns an empty GUID if the object is null or not an asset.

Parameters
assetAn asset instance.
Returns
The GUID of the asset. Returns empty GUID if the asset is null or not an asset.
See also

Definition at line 970 of file Asset.File.cs.

971 {
972 if (asset == null)
973 return new GUID();
974
975 // explicit variable + assign because Unity 2021 has both long and int variants of the TryGetGUID* method
976 var localId = Int64.MaxValue;
977 return AssetDatabase.TryGetGUIDAndLocalFileIdentifier(asset, out var guid, out localId)
978 ? new GUID(guid)
979 : new GUID();
980 }