Search Unity

  1. 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

Unity Prefab Mode in Context now in 2020.1 beta

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

  1. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,839
    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:
    43
    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

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,839
    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:
    511
    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,066
    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

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,839
    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.
     
  7. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,066
    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

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,839
    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:
    118
    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:
    325
    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:
    2,800
    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

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,839
    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:
    245
    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:
    325
    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:
    3
    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:
    119
    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:
    5,239
    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:
    119
    Good idea.
     
    Peter77 likes this.
  20. RemiOuterminds

    RemiOuterminds

    Joined:
    Mar 23, 2017
    Posts:
    3
    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 at 1:54 PM
  21. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    119
    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.
unityunity