Search Unity

What does "PrefabUtility.IsPartOfPrefabAsset" actually mean?

Discussion in 'Prefabs' started by CDF, Sep 17, 2020.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    It's confusing trying to determine all the different states a prefab can be in.
    From the docs:

    https://docs.unity3d.com/ScriptReference/PrefabUtility.IsPartOfPrefabAsset.html

    "True is the object is part of a Prefab Asset."

    Yes, but what does that actually mean? When is it true and when is it false.

    It's true when:
    1 - it's not open, not part of scene or stage?
    2 - It's not open but still selected in inspector in project window?
    3 - You load the reference using AssetDatbase.LoadAssetAtPath?

    it's false when:
    1. - it's open, part of scene or stage?
    2. - it's been loaded using PrefabUtility.LoadPrefabContents?

    I'm having some issues with Dirty state and git noise.
    Turns out I've been using OnValidate to do some stuff, but OnValidate was being called on prefabs that weren't actually open. Just want to make sure that using PrefabUtility.IsPartOfPrefabAsset is the only check I need to ensure data isn't changed if the prefab isn't an instance or is open in prefab mode.
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892