Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Change base of prefab variant.

Discussion in 'Prefabs' started by koirat, Feb 25, 2019.

  1. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    102
    Is there a way to change base of a prefab variant, or add new base to prefab without a base ?

    Or we got no other choice than completely rebuild our prefabs and all references associated with them.
     
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    449
    Check this presentation for some ideas of the refactorings you can do

     
  3. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,656
    It's not something that there exists a good clean workflow for at the moment.

    Given it's not possible to use an existing Prefab as a base, but a new one has to be created, what would be the best workflow in your opinion? To be able to specify that Cat should have a base (Animal) and Animal will initially be just a single empty GameObject? This way you could selectively apply overrides from Cat to Animal afterwards. The problem with the current approach is that there is no operation which is the "reverse" of applying overrides.

    To be clear, the various refactoring operations that are currently possible were not specifically designed (apart from some minor workflow tweaks to reduce confusion) - they are just side effects of how the Prefabs system works. So if they don't seem ideal, it's because it's not a feature we actually spent time on, but one that just appeared as a (limited) bonus by itself. Like many potential improvements, it's something we can definitely see it would be nice to improve upon if time and resources permits.
     
  4. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,656
    Well, it's not that simple. Not all overrides can move freely around.

    • Property override: If you apply it to the base, then it's just the new value of the base. Even if you make the property an override again in the Variant, you wouldn't get the previous original value of the base back.
    • Added components and added GameObjects: These work well for moving between base and Variant.
    • Removed component: If you apply this to the base, it will just destroy the component on the base. This is not reversible, so you can't "extract" a removed component override from a base to the Variant and cause the component to exist again on the base that way.
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    102
    For me it would be ok even if the content was completely deleted (or moved into some new container inside prefab "OldContent" or some other name :) ) during the change of base prefab.

    I can always repair what I have to.
     
    Bill-Sansky likes this.
  6. Bill-Sansky

    Bill-Sansky

    Joined:
    Oct 2, 2016
    Posts:
    60
    I agree. Giving us access to the possibility, even if only through PrefabUtilities and with the risk of losing data would be a great plus.
    It happens to me regularly now that I did not foresee a need in one of my prefab that has multiple variants, and now need to make it derived from another base. I would be ok with having to fix stuff around since this would still take way less time than having to delete all my prefabs and redo them all over again.

    By the way, it is quite frustrating that you cannot change the hierarchy or delete game objects in variants: you can delete components which lets you practically delete the game object by removing all the components, and passing the game object inactive and tagged EditorOnly, but it would be great to have a cleaner way to do that
     
    Spy-Shifty, _met44 and macagu like this.
  7. bfurtwangler

    bfurtwangler

    Joined:
    Mar 1, 2019
    Posts:
    2
    I very frequently run into issues caused by these limitations, it's like Prefabs are so close to being really good, but they just miss the ball on a few things. Resorting to hacks like Bill-Sansky described is pretty disappointing, but unfortunately seems like all we can do at the moment. Hopefully this will be improved in 2020.

    Imagine if git only let you add or modify lines of code, but you could never delete a line of code (although strangely you can delete whitespace)... just comment out lines you don't want until git 2020 yolo!
     
    Bill-Sansky likes this.
  8. mykillk

    mykillk

    Joined:
    Feb 13, 2017
    Posts:
    59
    The way I just worked around this was to create a dummy prefab variant of the new base I want to change to. Opened it up in a text editor to get the File ID & GUIDs of the new base prefab. Then I opened up my existing prefab variants and changed the referenced IDs. This worked cleanly because the old & new base prefab had the same Component layout.

    I think Unity really should have built-in support for being able to change the base prefab. Even if that means the values in the variant get reset. Because as the others have mentioned, it is a much bigger ordeal when you have to delete and recreate alllllll your prefab variants when the base prefab needs to be changed. And you still end up with default values in the new variants anyway.
     
    Last edited: Oct 3, 2019
    AndrewKaninchen and Bill-Sansky like this.
  9. AndrewKaninchen

    AndrewKaninchen

    Joined:
    Oct 30, 2016
    Posts:
    89
    Yeah, really think this should be a thing. I've been thinking about some ways to implement an idea I have and just hit this limitation. It's a pretty big deal for the system I was thinking about, as it would be much better to use if a designer could create a specific implementation of something and then, after that, abstract it's functionality as a parent class. It's actually something quite common in class-oriented programming as well, to be fair, so it makes sense as a viable workflow for something which is pretty much that.