Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Feedback IsAnyKindOfPrefab and the lack of prefab-ness in the prefab stage

Discussion in 'Prefabs' started by idbrii, Oct 17, 2020.

  1. idbrii

    idbrii

    Joined:
    Aug 18, 2014
    Posts:
    28
    It seems useful to me to have a function that tells you if an asset is in any way part of a prefab?

    PrefabStage.IsPartOfPrefabContents works -- but only in the stage.

    PrefabUtility.IsPartOfAnyPrefab works -- but not in the stage.

    Probably the answer is for me to make a helper function:

    Code (CSharp):
    1. public static bool IsAnyKindOfPrefab(GameObject go)
    2. {
    3.     var stage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
    4.     return UnityEditor.PrefabUtility.IsPartOfAnyPrefab(go)
    5.         || (stage != null && stage.PartOfPrefabContents(go));
    6. }
    7.  
    (Does that actually cover it?)

    My real problem is that I find it unintuitive that none of the PrefabUtility functions return true in the prefab stage. I think I understand why: the prefab stage is a place where your asset isn't a prefab, but nested prefabs *are* prefabs. I'm not sure what benefit I get from this distinction. It seems like things would work more how I expect if the prefab stage worked like an empty scene with an instance of my prefab in it. I guess that's just how I'm used to editing prefabs (from before the new workflow), so that's still how I think about it.

    Edit:
    Another example that confuses me: how can I get the asset path for a prefab? might be PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot() or PrefabStageUtility.GetCurrentPrefabStage().prefabAssetPath(). If I'm adding some editor buttons, I need to check two things every time.
     
    Last edited: Oct 17, 2020
unityunity