Search Unity

  1. Click here to receive a gift with your purchase of Unity Pro or Unity Enterprise.
    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

Any way to open a RectTransform prefab without the environment Canvas?

Discussion in 'Prefabs' started by zvinless, Oct 28, 2018.

  1. zvinless

    zvinless

    Joined:
    Oct 6, 2014
    Posts:
    18
    Having the UI Environment is really useful for things that use CanvasRenderers, but I have prefabs with RectTransform roots that are rendered using other kinds of renderers (e.g. TextMeshPro uses a MeshRenderer). Is there a way that I can have these open in the Regular Environment instead?
     
  2. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    121
    Hi,

    If you need more control over the environment objects in Prefab Mode you can hook in and customize it to your liking from the event:
    PrefabStage.prefabStageOpened
    .

    See a script example here:
    https://github.com/Unity-Technologi...ets/Editor/Scripts/CustomPrefabEnvironment.cs

    (and then leave the Environment scenes empty in the Editor settings)

    E.g: Use the
    prefabStage.prefabContentsRoot
    to check what kind of environment and reparenting you want to setup.
     
  3. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    121
    We are considering changing the current logic to match what you suggested by checking if the opened Prefab has a RectTransform but not a CanvasRenderer then we would use the Regular Environment scene instead of the UI Environment.
     
  4. zvinless

    zvinless

    Joined:
    Oct 6, 2014
    Posts:
    18
    Awesome, thanks! The CustomPrefabEnvironment is certainly good for now :).
     
  5. zvinless

    zvinless

    Joined:
    Oct 6, 2014
    Posts:
    18
    I'm able to destroy the Canvas on the prefabStageOpened event, but it reappears when I save my project. Does that reload prefab mode without firing the event?

    Also, related to the environment choice logic, TextMeshPro objects (3D Object/TextMeshPro - Text) have both a RectTransform and a CanvasRenderer component (it's hidden in the inspector), so maybe there should be some further way to decide?
     
  6. zvinless

    zvinless

    Joined:
    Oct 6, 2014
    Posts:
    18
    Awesome to see this got addressed in the latest beta! I went ahead and opened (Case 1103782) for the TMP/hidden Canvas Renderer issue. Not sure what the most robust way would be to determine which environment to use without getting a little special case-y.
     
unityunity