Search Unity

Made With Prefabs

Discussion in 'Prefabs' started by runevision, Jun 18, 2018.

  1. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,502
    Show what you've made with the improved Prefabs features! Write a bit about what you did with the new features that you couldn't easily do before.
     
  2. BAIZOR

    BAIZOR

    Joined:
    Jul 4, 2013
    Posts:
    70
    upload_2018-6-20_11-52-20.png
    Really optimized nested and variants prefabs memory.
    70kb instead of 600kb+ in previous unity versions.

    Good job Unity team. Keep testing :)
     
    PixelJ, rakkarage and Prodigga like this.
  3. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    62
    What? Unity, why did you say nothing about the performance improvements?
     
  4. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,502
    Well, we are just as surprised as you. ;) There should be no difference in performance at runtime since all Prefabs are baked out into hierarchies of regular GameObjects. None of all the new Prefab features exist at runtime; only in the Editor.
     
  5. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    38
    Should the object size improve load time / initialization times even at runtime?
     
  6. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    62
    That means you didn't change any prefab architecture under the hood? I've read something about bad design decisions in prefabs, can you tell: is that true or you have no plans on improving prefabs under the hood?
     
  7. BAIZOR

    BAIZOR

    Joined:
    Jul 4, 2013
    Posts:
    70
    I'm not talking about RAM optimization. I'm talking about build size, very important for mobile.

    For example, in previous versions of Unity if you have 5 prefabs with just different materials they could be 60kb for each.
    But if you now create one original prefab and 4 variants of the original. It could be 60kb for original and 3-5kb for everyone else. Great optimization if you have hundreds of prefabs like that ;)

    upload_2018-6-21_15-26-16.png

    Head Bot - original prefab
    Head Bot Variant 1 - the variant of original prefab with changed materials and transforms

    Cluster - original prefabs which exist from 9 Head Bots and 9 Head Bot Variants
    Cluster Variant 1 - original cluster but with few changes

    In previous unity version if create something like that structure the general size of prefabs could be 600kb +
    For example, Head Bot (17kb), Head Bot Variant (17kb), Cluster (17 * 9 * 2 = 306kb) Cluster Variant (306kb). And we have 17 + 17 + 306 + 306 = 901kb if using previous Unity version prefabs. I guess unity zips it in build with the lower price, but one deal is zip 901kb and another one zip 60kb :D
     
    Last edited: Jun 21, 2018
    rakkarage and interpol_kun like this.
  8. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    2,012
    .prefab extension are editor files. Rune explained that the prefabs get flattened at build time so I don't expect much improvement. What's your size delta on the builds?
     
    runevision, Jes28 and rakkarage like this.
  9. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,502
    Prefabs before existed only in the Editor, not at Runtime, and that is still the case now as well. We did change Prefabs under the hood a lot, but it has no effect on runtime since there's no concept of Prefabs at runtime. You can "instantiate Prefabs" at runtime, but you're really just loading and duplicating baked out GameObject hierarchies, unlike instantiating Prefabs in the Editor, where you get a proper Prefab instance that can have overrides etc. You can see the same in Play Mode, where when you instantiate a Prefab as part of your game, it will look like regular GameObjects and by default have "(Clone)" appended to the name.
     
    5argon and mahdi_jeddi like this.
  10. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,201
    I'm making a city building game. Now I can have a base building to act as a template, then just modify the mesh/collision gameobjects for each variant, and add new MonoBehaviours. Also, the same for different types of NPC's.

    030_BuildingTest.PNG

    Maybe I can go even further and make a base "Placeable" prefab template, then "BuildingBase" is a variant of that, then the actual visible buildings are variants of BuildingBase... Each building would be a variant of a variant. o_O I haven't tested that.

    There are three things Unity made recently that made this game easier to make - Runtime NavMesh, GPU Instancing and now Prefabs.
     
    Last edited: Jun 22, 2018
  11. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,502
    For those who haven't yet seen the Unite LA 2018 keynote, Joachim Ante and Martin Kümmel showed off Unity's new MegaCity demo which makes heavy use of nested Prefabs, Prefab Variants, and the new Prefab workflows (along with all the new ECS features!) to create a massive city in a very short amount of time by just a couple of people.

    Here's a link to the keynote beginning from where this is shown:
     
    Alverik and laurentlavigne like this.
  12. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    2,012
    The demo itself is impressive but it only shows a subset of how artists use prefabs, which in this case is moving objects around, and because that subset is limited the demonstration doesn't show the shortcomings of the new prefab workflow.
     
  13. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,502
    Yes, that applies to every demo, ever. For a flexible toolset, no demo could ever show every possible way it can be used. This thread is for showcasing various examples of ways that the Prefabs are being used. :)
     
  14. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    2,881
    Man, you feel bitter about prefabs so much...
     
  15. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    2,012
    Not Bitter, empassionate - about having this cornerstone ironed out to perfection because I'll be living with them for the next 5 years.
     
    RDeluxe likes this.
  16. SergeantBiscuits

    SergeantBiscuits

    Joined:
    Jul 22, 2012
    Posts:
    12
    Hi all. I've been using Unity in both a hobbyist and professional capacity for about seven years now, and I cannot fully express how much I love the new prefab workflow. I've been one of those rabid "why don't we have nested prefabs?" guys since I first installed Unity... When I installed the new alpha preview, I almost felt like I could cry. It's beautiful. It's completely changed the way I approach almost every element in my games, and being able to treat objects more like object-oriented programming (with inheritance and such) is an absolute godsend.

    Yes it has bugs, yes it's a little clunky, yes it has a little bit of a learning curve... but overall, it unlocks potential in Unity unlike any other update I've seen you guys put out. (And I've already seen it improved tenfold with the .1.0a8 patch; I'm sure by the official release it will be more or less rock-solid.)

    Anyways, big thanks to the Unity devs for the hard work and for listening to us (and for the community for making noise!) From myself and my protagonists--you all rock!



     
  17. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    579
    I fully support the new nested prefabs feature. It will be an awesome tool and will greatly improve Unity's workflow in most cases.

    However, in some cases it is best to generate prefabs w/ scripts (not drag & drop). In this case the new prefab system is breaking my prefab workflow. Currently I use an editor script to generate all prefabs (this makes new prefabs from scratch then I call CreatePrefab or ReplacePrefab). I do this because I have many prefabs with complex hierarchies and subtle differences (slight variations in size, or texture, or scripts, or rigidobdy, or colliders, etc.). A drag & drop nested hierarchy will not work well because many of these differences are placed throughout the hierarchy. See video below.



    After creating my prefabs I use PrefabUtility.CreatePrefab or PrefabUtility.ReplacePrefab w/ ReplacePrefabOptions.ReplaceNameBased.

    The PrefabUtility.ReplacePrefab w/ ReplacePrefabOptions.ReplaceNameBased feature works great because it maintains my serialized scene links. The removal of ReplaceNameBased has me extremely worried. I tested the new PrefabUtility.SaveAsPrefabAsset and it breaks all serialized scene links.

    For those of us that generate & adjust prefabs w/ scripts what is the new alternative to the now obsolete PrefabUtility.ReplacePrefab w/ ReplacePrefabOptions.ReplaceNameBased? Is it possible to add ReplaceNameBased option into the new PrefabUtility.SaveAsPrefabAsset (or something similar like giving control over the serialized ID's foreach object/script in the prefab) so serialized scene links aren't broken when a new prefab is saved? Thanks in advance.

    You can see how the script generated monster prefabs in operation here.
     
    Last edited: Jan 9, 2019
    golmae likes this.
  18. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    3
    Can I ask, are nested prefabs a thing now in Unity? :)
     
  19. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    62
    Yes, since 2018.3
     
  20. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    3
    Superb!