Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official Prefab Mode in Context now in 2020.1 beta

Discussion in 'Prefabs' started by runevision, Mar 18, 2020.

  1. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Unity 2020.1 has a new improvement to the Prefab workflows called Prefab Mode in Context.

    With Prefab Mode, you could always edit a Prefab in isolation. Now you can also open a Prefab in context. When you open Prefab Mode this way, you can see the context of the Prefab instance in the Scene view (but locked for editing) even though you are not editing the instance but rather the Prefab Asset itself (like always, in Prefab Mode).


    You can try it out today in the Unity 2020.1 beta. Check out the documentation too.

    Editing in Context
    When you open Prefab Mode via a Prefab instance in the Hierarchy window, this opens Prefab Mode in Context. When you open Prefab Mode this way, you can see the context of the Prefab instance in the Scene view even though you are not editing the instance but rather the Prefab Asset itself. So if you for example open Prefab Mode in Context via a Prefab instance in a scene, then you can see the surroundings in that scene while editing the Prefab and the Prefab is shown with the same lighting conditions as in the scene.


    A Prefab opened in Prefab Mode in Context, with the surrounding context displayed in gray scale.
    (Pictured assets from the Asset Store package POLYGON - City pack)


    If you have a Prefab instance that you do not want to open in context, but rather want to open in isolation, you can hold down the Alt key while clicking the Open button or the arrow button to open Prefab Mode. It’s also possible to setup a custom shortcut in the Shortcuts window for the command “Stage > Edit Prefab in Isolation”.

    Controlling how the context is displayed
    The visual representation of the context is by default shown in gray scale to visually distinguish it from the Prefab contents being edited. However, a control in the Prefab bar can be used to set it to any of the following states:
    • Normal - the context is shown with its normal colors
    • Gray - the context is shown in gray scale
    • Hidden - the context is hidden entirely so only the Prefab content is visible

    The Prefab Mode controls in the Prefab bar in at the top of the Scene view, including the Context control and the Show Overrides toggle

    The objects that are part of the context are not selectable, nor will they show in the Hierarchy. This is to allow you to focus on editing your Prefab without accidentally selecting other unrelated objects, and without having a cluttered Hierarchy window. However, when you move objects around that are part of the Prefab contents, you can use the snapping features in Unity to snap to objects in the context, provided the context is not set to Hidden.

    Previewing overrides from the Prefab instance
    In Prefab Mode in Context, the Prefab contents are shown at a position that matches that of the Prefab instance it was opened through. This means the root Transform of the Prefab contents may be previewed with different position and rotation values than the Prefab Asset actually has. These values cannot be edited in Prefab Mode in Context. If you need to edit them, you can either open the Prefab in isolation, or you can select the Prefab Asset in the Project window and edit the values in the Inspector.

    Apart from the root Transform properties, a Prefab instance can have other properties overridden as well, which may drastically change its appearance compared to the Prefab Asset it’s an instance of. You can preview these overridden values from the Prefab instance while in Prefab Mode in Context by enabling the “Show Overrides” toggle in the Prefab bar. While enabled, any properties that are overridden on the Prefab instance are previewed the same way on the Prefab contexts and cannot be edited. To be able to edit those properties, disable the “Show Overrides” toggle again.

    Let us know how this is working for you!
    Is the Prefab Mode in Context feature useful in your workflows? What do you use it for?

    We think the feature may be useful particularly for level design tasks and for UI (uGUI) work but let us know what your own experience is.

    Are you encountering any issues? Bugs or things that are confusing or unclear? Let us know!

    The user manual page for the feature are not yet ready, but the above covers most of what it's going to say about the feature. If anything needs to be explained better, let us know as well!
     
    Last edited: May 19, 2020
    Wattosan, Smurrph, Kirsche and 10 others like this.
  2. SirIntruder

    SirIntruder

    Joined:
    Aug 16, 2013
    Posts:
    49
    Is there a way to control gray out for emitted draw calls? (Graphics.Draw... methods and renderers created at runtime in custom batching systems). I may emit some draw calls based on prefab content, but Unity isnt aware and would simply gray out everything.

    At minimum we should have an api to change prefab stage GrayOut mode from code, if we know the in built check is not good enough for some cases
     
    Last edited: Mar 18, 2020
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Prefab Mode is not part of Play Mode. Even when the editor is in Play Mode, objects in Prefab Mode don't go into Play Mode. As such, runtime graphics APIs are not relevant for Prefab Mode as far as I understand.

    Even if you use runtime graphics APIs in Edit Mode (so they're visible also when not in Play Mode), we can't give runtime APIs knowledge of Editor specific concepts like Prefab Mode, since those concepts don't exist in the runtime engine.

    That said, we're interested in seeing if we can address your use case. If you file a bug report with your project and how it's using these APIs in Prefab Mode, we can have a look at whether there's something we can do. Thanks!
     
  4. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    If this is useful? :) This is how it should've been done from the beginning. :) Love this feature.
     
    Shizola likes this.
  5. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,276
    Are there plans to make Prefab Stages more open ended via API's? For example, being able to open a stage and create a gameobject inside of it as opposed to just a prefab?
     
  6. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Prefab Stages are for Prefabs, but in 2020.1 you can create your own type of stage as well by inheriting from PreviewSceneStage (which PrefabStage also inherits from):
    https://docs.unity3d.com/2020.1/Documentation/ScriptReference/SceneManagement.PreviewSceneStage.html
    https://docs.unity3d.com/2020.1/Doc...e/SceneManagement.StageUtility.GoToStage.html

    However, this is not really related to the Prefab Mode in Context feature.
     
    Thaina likes this.
  7. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,276
    That's what I thought, but I couldn't find the docs on it. The reason I brought it up here was to ask if this in context mode will also be supported in the generic stage api
     
  8. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    The ability to see the context is implemented in PrefabStage and isn't built into PreviewSceneStage. There are Prefab specific aspects to it, like hiding the instance in the scene so it doesn't overlap with the opened Asset which is positioned in the same place. We'd be happy to hear about use cases for showing context in custom stages so we can have it help inform our prioritization.
     
  9. Bastienre4

    Bastienre4

    Joined:
    Jul 8, 2014
    Posts:
    191
    Good job. Prefab workflow really needed this feature, especially for UI related prefabs.
     
    Thomas-Mountainborn likes this.
  10. Hyp-X

    Hyp-X

    Joined:
    Jun 24, 2015
    Posts:
    432
    I tried this, but it doesn't show the prefab at the right location.
    It shows the prefab at the Position in the prefab, not the Position where it is on the map.
    This makes the context part not work at all.
    Testing this in 2020.1.0b12
     
  11. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,521
    Prefabs in place is very welcome, thanks for that!

    Will you also add anway to customise prefab previews?

    The thumbnail gallery in the project browser shows prefabs too dark, and there is currently no way to change the background color and the light intesity of the generated thumbnails.
     
    joshcamas likes this.
  12. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    We haven't seen this issue before. Do you have any non-uniformly scaled Transforms as parents of the Prefab instance in question? If it still happens in the latest beta, can you file a bug report and post the case number here so we can investigate?
     
  13. Flow-Fire-Games

    Flow-Fire-Games

    Joined:
    Jun 11, 2015
    Posts:
    305
    Guys please, the new Prefab workflow was already cumbersome to work with when you want to move or replace / take out things from a prefab (requiring to unpack) but now this is hidden in a second drop down menu on top - this is just painful

    How about you enter a third button to the popup that appears when you try to move something in a prefab
    that says "Unpack Prefab" / "Unpack Completely" - This would make this much less painful and save the user experience. There is nothing worse than multiple layers deep drop down menus for common actions.

    upload_2020-7-5_18-13-39.png

    Especially 3D Artists import a lot of meshes which are then always prefabs which need to be unpacked each time
     
  14. Hyp-X

    Hyp-X

    Joined:
    Jun 24, 2015
    Posts:
    432
    It was user error on my side.
    I though Alt+click was context mode and Click was isolation.

    The issue was that some custom rendering stuff was (like our terrain system) is still visible in isolation.
    I need to find a way to support this workflow (although not being default, most people in our team won't use it)
     
  15. kzy419

    kzy419

    Joined:
    May 26, 2017
    Posts:
    1
    ●Prefab AllApply
    ●Unpack Prefab Shotcut
    These two are absolutely necessary Please

    googleTranslate
     
    Flow-Fire-Games likes this.
  16. RemiOuterminds

    RemiOuterminds

    Joined:
    Mar 23, 2017
    Posts:
    10
    Is there a way to open a prefab instance in your scene with in-context prefab mode using script? I know I can open the asset, but I'd really like to be able to open it in-context.
     
  17. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    217
    AssetDatabase.OpenAsset()
    has an optional
    int line
    parameter, if you pass the instanceID of the Prefab instance object then we will open Prefab Mode In Context of that instance.

    Example: If you have a Prefab instance in the scene you can use:
    GameObject prefabAsset = PrefabUtility.GetOriginalSourceOrVariantRoot(yourInstanceGameObject);
    AssetDatabase.OpenAsset(prefabAsset, yourInstanceGameObject.GetInstanceID());


    We know that this approach seems non-obvious and intend to improve this with a more explicit API in the future.
     
    RemiOuterminds and Peter77 like this.
  18. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Maybe ask the docs team to put it in the scripting documentation in the meantime? It probably takes a good amount of time until a more explicit API lands.
     
  19. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    217
    Good idea.
     
    Peter77 likes this.
  20. RemiOuterminds

    RemiOuterminds

    Joined:
    Mar 23, 2017
    Posts:
    10
    PrefabUtility.GetOriginalSourceOrVariantRoot doesn't seem to exist, but I managed to make if work with other functions in PrefabUtility

    Thanks for the help


    Code (CSharp):
    1. var prefabAsset = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(myPrefabInstanceInScene);
    2. AssetDatabase.OpenAsset(AssetDatabase.LoadAssetAtPath(prefabAsset, typeof(GameObject)), myPrefabInstanceInScene.GetInstanceID());
     
    Last edited: Oct 28, 2020
  21. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    217
    Ah my bad, it is one of our internal methods.
    GetPrefabAssetPathOfNearestInstanceRoot()
    simply wraps
    GetOriginalSourceOrVariantRoot ()
    to get the asset path. So you found the correct public method.
     
    RemiOuterminds likes this.
  22. Demerzel_

    Demerzel_

    Joined:
    Mar 31, 2015
    Posts:
    4
    if you re-using elements, which should scale according to parents and use a corner anchoring system, then it's an incredibly inconvenient option
    is there any way to disable it?
     
  23. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    upload_2021-5-21_14-48-59.png
     

    Attached Files:

  24. kadd11

    kadd11

    Joined:
    Mar 11, 2018
    Posts:
    33
    @runevision, on the topic of what @SirIntruder asked, even if the graphics apis don't know about context mode, etc, how would one go about honoring that behaviour if they were using the Graphics.DrawX apis in edit mode? More concretely:

    Say I am drawing things with the graphics apis, and the things I'm drawing are associated with a certain gameobject. I want to honor the visibility state based on whether the associated gameobject would be visible given the prefab stage mode and the editor render mode (Hidden, Normal, Gray). There doesn't seem to be a way of accomplishing this right now. The render mode setting doesn't seem to be exposed publicly, so I can't do it manually and any of the apis that seem like they might help don't return what I would expect (StageUtility.IsGameObjectRenderedByCameraAndPartOfEditableScene, StageUtility.IsGameObjectRenderedByCamera), for example they will return true for a scene gameobject even if the render mode is set to "hidden".
     
  25. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    Rune's not working for Unity anymore, so you probably won't get any answers from him :p

    It seems like the data is stored in
    Code (csharp):
    1. ScriptableSingleton<StageNavigationManager>.instance.contextRenderMode
    , so you'll have to read that through reflection. Ideally we'd just be able to check the value, but Unity's being Unity here.
     
    Bastienre4 likes this.
  26. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    132
    While I like this functionality quite a bit, is there a way to change the default open mode for prefabs? I find that 90% of the time I still want to open prefabs in isolation and would like to change the default behavior.
     
  27. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    Opening the prefab opens it in the mode you last had selected when you closed prefab mode, doesn't it?
     
  28. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    132
    Hmm, don't think so? Sorry, I should have been more specific, I'm attempting to open the prefab using the little arrow to the right of the object name in the inspector. It always seems to 'open in context' where I'd like to change the behavior to 'open in isolation' by default. Not a big deal, but those extra clicks adds up.
     
  29. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    217
    Using the 'Alt' modifier key when clicking the arrow in the Hierarchy will open in isolation instead of in context. Does that work for you?
    Also note that you can bind a shortcut key to open in the mode you want:

    upload_2021-11-23_8-38-56.png
     
  30. Janeator

    Janeator

    Joined:
    Jan 14, 2017
    Posts:
    8
    These are all sloppy workarounds. Where is an option to just make it work as it was before? Toggle alt-click behaviour, if you will.
     
  31. GhostTownGames

    GhostTownGames

    Joined:
    Dec 15, 2015
    Posts:
    6
    It would be very useful to change the default behaviour for opening prefabs in the preference screen. Particularly I keep accidentally opening an original prefab "in context" from the a varient prefab I'm working on"in isolation" which is very confusing. I just don't use the in context very much and would like to not have to remember to hold ALT every time i click Open.
     
  32. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,276
    If you choose in isolation from the drop down on the top bar, it should default to that forever right?
     
  33. Mariusz-Born7

    Mariusz-Born7

    Joined:
    Sep 4, 2015
    Posts:
    40
    There is a bug. When you go into prefab mode in context and select "Hidden", custom pass volume (Script) placed in some GameObject in the scene (not in prefeb) doesn't work. It works when you select "Normal" or "Gray". HDRP 2021.3.6f1.
     
  34. alexsmith123

    alexsmith123

    Unity Technologies

    Joined:
    Jan 11, 2022
    Posts:
    23
    Hi,
    If you find a bug could you please report it, and attach a repro project with steps to reproduce it?