Search Unity

Feedback Prevent Prefab instance overrides

Discussion in 'Prefabs' started by zander_m, Jun 4, 2019.

  1. zander_m

    zander_m

    Joined:
    Feb 7, 2019
    Posts:
    15
    Do you think we could get a way to mark a Prefab instance in a scene as "Not Allowed to have Overrides"?

    I'm working on a project with several unique prefabs placed into a scene that we never want to create additional instances of. These particular prefabs exist to help minimize merge conflicts and thus we always want changes to be made directly to the Prefab Assets. I'm frequently finding myself resolving complex merges where edits to these prefabs are "randomly" spread between the Prefab Asset and the Prefab Instance (overrides) because it's so easy to make changes from the Scene view and not apply them. These changes almost exclusively come from artists and designers who get confused by the technical complexities of the Prefab Instances + Overrides flow.

    In this situation, it would be fantastic to be able to mark a particular Prefab Instance in a scene as being "not allowed to have overrides" or some other form of "finalized".

    I think an ideal implementation of this would have the marked prefab not show it's children in the Hierarchy and only show it's prefab alignment in the Inspector when selected. Modification to anything other than the prefab alignment could only be done by opening and editing the Prefab Asset directly.
    This would prevent less technical contributors from unintentionally creating prefab overrides, help expose more users to the Prefab Editing workflow, and add additional clarity to how a particular prefab is expected to be used within a scene/project.

    (It'd be a bonus if double clicking this marked prefab instance in the hierarchy was a fourth option for opening the Prefab Asset in the Scene view for editing, maybe even automatically setting the current scene as the Editing Environment)
     
  2. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    We have the same set up, with core prefabs in a central scene that should not get overrides. We currently don't have any safeguards like you're talking about.
    There are a few inspector attributes you can use to hide everything in the inspector, have a look through the docs.
    There might also be some stuff on the asset store to Lock gameobjects
     
  3. zander_m

    zander_m

    Joined:
    Feb 7, 2019
    Posts:
    15
    Yeah, there are some hacky ways around it (similar to custom pre-2018 implementations of nested prefabs), they just aren't at all convenient. The HideInInspector attribute can sort of help, but afaik there's no way to apply it conditionally in order to leave the intended prefab editing workflow unchanged.

    I think you could maybe get close to the implementation I'm describing using a heavy coating of custom inspectors and managing HideInHierarchy flags yourself... but again, it's way more overhead and maintenance than any official implementation would be.
     
    Gretsok and JakobAnarkyLabs like this.
  4. EternalSpace

    EternalSpace

    Joined:
    Nov 12, 2019
    Posts:
    1
    It’s 2023, is there any progress?
     
  5. neviovalsa

    neviovalsa

    Joined:
    Jun 24, 2019
    Posts:
    52
    Was wondering the same, it would really help enforcing good architecture, can't wait for a feature like that to be implemented.

    In the meantime I wrote a simple Editor functionality to check whether there are any overrides in the currently open scene.


    Code (CSharp):
    1. [MenuItem("Tools/Find Overrides In Currently Open Scene")]
    2. private static void FindOverrides()
    3. {
    4.     string[] prefabPaths = AssetDatabase.GetAllAssetPaths().Where(path => path.EndsWith(".prefab", System.StringComparison.OrdinalIgnoreCase)).ToArray();
    5.  
    6.     foreach (GameObject gameObject in GameObject.FindObjectsOfType<GameObject>(true))
    7.     {
    8.         bool hasOverride = PrefabUtility.HasPrefabInstanceAnyOverrides(gameObject, false);
    9.         if (hasOverride)
    10.         {
    11.             Debug.Log($"Found GameObject {gameObject} with overrides: ", gameObject);
    12.         }
    13.     }
    14. }
    In the future I'd like to improve it to do that for all Scenes in the project, would then be nice to run it as a pre-commit hook if possible in some way
     
  6. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    582
    What you are asking for is a way to LOCK a Prefab and prevent any changes.

    That could be useful under certain circumstances. (Perhaps even with a password hahahaa)
    It would be nice to see.

    I have not tried it, just thinking out loud.
    Have you tried making that file "Read Only" in the File Explorer?