Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Handling Scene links within Prefabs

Discussion in 'Prefabs' started by Noblauch, May 19, 2020.

  1. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    256
    Hey folks,

    I have an annoying problem:
    I have a UI Prefab that is self contained, except the input cameras. The cameras can be rendering various other stuff that gets displayed in the UI via render textures.

    But everytime I have to revert the Prefab in the scene these linked cameras get thrown out, since they can't live in the prefab itself. I then have to go manually in and find all the places for cameras and relink them. Sometimes I end up doing that several times a day.

    Due this being a common problem (not only with cameras) are there any best practices on how to handle this? I tried to replace the camera with scriptable objects, but realized that they too can't link to scene prefabs, since they are basically prefabs aswell.
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,877
    What is your workflow? Why do you need to (frequently) revert the Prefabs in the scene? And if you do need to revert some things on the instances, why not only selectively revert the things you need to revert instead of using "Revert All" if you don't actually want to revert everything?

    You can use the Overrides dropdown on Prefab instances to choose what you want to revert. You can also use right click menus on individual components or individual properties to revert only those.
     
  3. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    256
    Hey runevision,
    thanks for checking by, that's why:
    RipPrefab.jpg
    This happens everytime I disable the prefab in the scene view. On the other hand I sometimes want to test something without changing the prefab, which I must save in order to test it.

    You can imagine, finding the 3 cameras in there takes quite a while every time and it's unnecessary work. Before I started this thread I was on the edge of writing an editor script, or some kind of dirty "apply camera by name" script, which really can't be the solution. Especially since the UI is getting bigger as the game grows.

    Greetings from Germany ;)
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,877
    Which version of Unity and which version of TextMeshPro are you using? Deactivating and activating a GameObject is not supposed to create overrides (except for the active toggle). I know there's been some issues with TextMeshPro in this area, but at least some of them, if not all, have been fixed in later versions.
     
  5. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    256
    @runevision Sorry, I've been away from the project a few days. As you can see the producer of this problem is the TMP Submesh feature. This happens on all components where something like <sprite=1034> is used as "text" to display sprites. The "overrides" are also non existent, nothing in these component has changed as far as I can tell, but Unity marks them as changed anyway.

    Unity Version: 2019.3.12f1
    TMP Version: 2.0.1
     
  6. GrayLightGames

    GrayLightGames

    Joined:
    Jan 14, 2015
    Posts:
    30
    I just put up a feature request to allow us to make prefab variants that are scene specific and can link to scene objects... sounds like that would solve your problem!
    https://forum.unity.com/threads/feature-request-allow-prefabs-to-reference-objects-in-scene.897350/

    I think your editor script would be a quick workaround... you could do it a number of ways. If you don't want to mess with stuff by name, you could add a component to your cameras with a list of objects and assign the camera to each list item on Start() or trigger with an editor command. Easy enough to remove if a bugfix makes it a moot point and probably less time to implement than one or two iterations of your camera hunting.

    Hope that helps, good luck!
     
  7. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    These issues should be resolved in version 2.1.0-preview.13 of the TMP package for Unity 2019.x.
     
  8. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    256
    I can confirm that TMP doesn't produce the overrides on 2.1.0-preview.13.
    However the problem in my case stays the same, since the RectTransforms seem to think they have to take over the TMPs job :D

    Overrides.png OverridesReason.png
     
  9. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,877
    It looks like some component is changing the RectTransform values without driving the properties. Do you know which component is changing the values?
     
  10. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    256
    Yes of course. Depending on the current window aspect ratio the ui gets updated to fit the screen when I enable it.
     
  11. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,877
    Not sure what you mean.

    RectTransforms by themselves do stretching to parent size etc. without changing any of the RectTransform values.

    Auto Layout Components like HorizontalLayoutGroup, ContentSizeFitter etc. do change values but drive the properties they change, so they're serialized as 0 and shown as non-editable in the Inspector.

    But here, the values are changed but also shown as editable (so not driven). I don't know what is the cause of that. Can you maybe record a video showing what you do that makes the fields go from not overriden to overrideen?
     
  12. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    256
    Yes, there are several Layout Groups involved. The Transforms are only editable when the mask is turned off. If they are enabled, the values are driven by the Layout Groups.
    The overrides occur when turning the object back off. When I turn it on, only the canvas gets overridden, because it changes from a default canvas component to one that inherits the "master" canvas.

    I can't make a video at the moment, sorry. This is my personal project, but I'm currently getting started with Addressables for work, ugh. :s
     
  13. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,877
    If you are turning layout components on and off, that's expected to create overrides on RectTransforms.