Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Difference between AssetDatabase.Contains and EditorUtility.IsPersistent

Discussion in 'Scripting' started by yasirkula, Feb 15, 2020.

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,365
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    1,871
    @yasirkula

    I think AssetDabase.Contains is something you use when you are sure you are only handling asset files (textures, prefabs, whatever). But like it says in EditorUtility.IsPersistent, it does this check:

    "Returns false if the object lives in the Scene."

    So it could be used to check if some Object you are handing isn't actually an asset file, but only part of a scene.

    Note - I've only actually used AssetDatabase.Contains...
     
  3. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,365
    Thank you for the reply. I believe AssetDatabase's documentation also states the same thing: "Returns false if object is not an asset (for example object in the Scene, or an object created at runtime)"
     
    eses likes this.
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    1,871
    @yasirkula

    Hah - so my idea about it wasn't true then... maybe someone else knows better.
     
unityunity