Search Unity

[Official] Share your Prefab Workflows!

Discussion in 'General Discussion' started by nikolinehoegh, Jun 14, 2017.

  1. nikolinehoegh

    nikolinehoegh

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    6
    Dear Unity Community,

    We are taking a long hard look at the Prefab system and want to engage you in a discussion.
    Our goal is to have you help us identify where we are not solving your problems or meeting your expectations.

    So -
    • What are you currently using prefabs for? What is your workflow for creating these prefabs?
    • Are there limitations, gaps, or issues when using Prefabs in your workflow?
    • Are you currently using any Asset Store plug-ins for Nested Prefabs? What problems does it solve? If you wrote your own, what does it solve that others don’t?
    To be clear, we are working on nested prefabs, among other workflow improvements. What we are looking for is specific use cases and problems that you have. Any screenshots or details you can provide will be much appreciated!

    We are also looking into the feedback given in this previous thread. We will be posting demos here as development continues, so stay tuned!

    Thank you,
    Prefabs team.
     
    JamesArndt and BAIZOR like this.
  2. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    I use prefabs for a lot of things and I would like to be able to edit them the same way in the project panel as in the hierarchy. For example my prefabs very often have child objects nested multiple levels deep, but the project window only shows one level deep. To edit them, I need to place them in the scene, make the edit (which often breaks the prefab link), and push the changes back to the project window. I'd to just be able to drag or ctrl+drag gameobjects from deep in a prefab's hierarchy in the project panel into the hierarchy of another prefab, like I could be doing in the hierarchy panel of the active scene.
    Also finding a prefab/material/script/asset isn't quite as straight forward as I'd like it to be. I make extensive use of the search function, but that (iirc) doesn't show the child objects of prefabs (which often enough is what I actually want to get to, to look something up or edit something) and when I click on the prefab and clear the search filter again, it doesn't keep the selected prefab focused in the window (at least not if the folder structure it was contained in isn't expanded already).
    Having those interactions more streamlined and intuitive would do a lot more for me than nested prefabs I think. I already get part of what nested prefabs would give me, by making scripts instantiate other prefabs as child objects, and with true nested prefabs I'd possibly mess more things up than it would save me time. But if the feature was there I'd give it a try. It might be useful.
     
    oobartez, Lo0NuhtiK, Farelle and 6 others like this.
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,332
    What are you currently using prefabs for? What is your workflow for creating these prefabs?

    Almost everything you interact with in our latest game (see sig) is a prefab. Enemies, save zones, powerups, chests, collectibles, you name it.

    There's nothing special about building the prefabs. We generally just stick the models and scripts together and drag-and-drop it into the prefabs folder. The prefab creation workflow is pretty intuitive, I don't have any issues with it as of now.

    I'd happily pay the price of a bit more complex prefab creation if that's necessary for nested prefabs.

    Are there limitations, gaps, or issues when using Prefabs in your workflow?

    Quite a few!
    Let me introduce you to the pugilists:
    The gang.png

    We have a minigame where you fight each of these in order. Each of those six share most details. The transform hierarchy is an exact match, and the same components are attached to the same transforms. The exceptions are:
    - a bunch of settings deciding things like health, attack speed, range, etc. on a MonoBehaviour
    - the size and positioning of some hitboxes and damage boxes.
    - the model

    We would love for this to be one prefab with six variants, but Unity doesn't support that, so this is six prefabs. If we change something (like adding a script that handles death reactions to the root of the prefab), we need to update each of the six prefabs in exactly the same way.

    This pattern repeats itself a lot. We have thorns that you take damage from walking into. But different environments need different models for the thorns, so we need one copy of the thorn prefab for each environment. The same goes for doors, chests, and so on.

    This causes big problems! Say we add a sound when chests open. Now we need to attach an audio source and a sound to every single chest prefab. If we forget one, then we've got a bug, and we always forget one :p
    So that's the kind of workflow we need nested prefabs for, mainly. Instances where a lot of prefabs differ only by model and script values.


    A related problem is replacing models. If you have eg. a monster prefab, and want to replace the model with a new one (due to changes in the rig), that's a bit of a pain. We often have a bunch of bones in the model referenced in different scripts on the prefab, and quite a few scripts and custom objects attached to bones.

    The manual workflow involves finding every single script, look at every single field for ones that reference a bone transform, and drag and drop in the equivalent bone from the new model. Then we need to find every single custom script and object in the old bone hierarchy and transfer those to the new one.
    This is very bug-prone and time consuming. It used to take about half a day to update the model of our main characters (although most of that was spent looking at the fbx importer window). We've since written some editor scripts to automate the process both for replacing models and transferring animation settings, but those are pretty complex and probably completely out of reach for somebody that's not got a programmer on their team (so 1-3 person teams using something like Playmaker).

    Are you currently using any plug-ins for Nested Prefabs?

    Nope.


    This should be a priority, it's really painful to have to drag the prefab into a scene to work with it. A dedicated prefab window would be nice, but just being allowed to fold them out all the way in the project view would be a very big improvement that should be easy to implement.

    The inspector already supports it, if you click something deep in a prefab hierarchy in the scene and use the prefab Select button in the inspector, the object gets selected at the correct dept in the project view.


    EDIT: You should move this thread to the Editor/Scripting forums or make a post there referencing the thread. I think a lot of people read those that doesn't read the general (non-technical) forums.
     
    Deleted User, Meceka, alfish and 4 others like this.
  4. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    I agree with that. It would be nice to be able to mark a property as "override". Override properties should not be updated when the prefab is modified and the button "apply" pushed. This would allow having multiple prefab instances but with different script values/configurations. At least, I think it would be useful and remove a lot of pain :)
     
  5. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,500
    • What are you currently using prefabs for? What is your workflow for creating these prefabs?
    I've used them for lots of things. Anything from templates of things that are populated at creation time, all the way to clunky copies with minor changes which clutters the project. I've found that over time I've moved toward keeping more data and prefabs in the project rather than putting things in the scene. Anything in the scene is only for that scene, so in terms of re-usability, prefabs or heavy project-level data driven game contents are critical.

    In terms of workflow the only good way to really create prefabs is to make something in the scene and then drag it into the project hierarchy when done.
    • Are there limitations, gaps, or issues when using Prefabs in your workflow?
    Editing more than one level deep on a prefab requires you to bring it into the scene which is constantly a nuisance.

    At the bare minimum I think prefabs are used for templates for types of Items. I've done some work where prefabs were only used as a template for a type of thing or item, then at runtime it spawns the template and populates it in the scene based on a given ScriptableObject. On the other hand I've also done a lot of work where prefabs are done like @Baste uses them and you run into issues with tons of copies of something very similar. I think most people use them this way. This can be solved with other design architecture - specifically by referencing chunks of the prefab as ScriptableObjects - but I don't think the majority of developers are doing this.

    Prefab instances kind of help work as variants but only if they exist in the scene. If you made them a prefab then poof, you're compounding your multiple copy design issue. Overall I've more or less just come to the conclusion that prefabs are just best meant to be a conglomeration of ScriptableObject references.
    • Are you currently using any Asset Store plug-ins for Nested Prefabs? What problems does it solve? If you wrote your own, what does it solve that others don’t?
    I'm not using Nested Prefab plugins, and I don't really want to write my own. I think the existing prefab setup is functional enough to justify using it without rolling your own or buying a Nested Prefab plugin. I don't even really want to explore the idea of using them unless it's an official solution. I'd worry about maintenance, being version locked, not having source control, or some bug destroying data accidentally. There is at least a reasonable degree of safety using Prefabs and ScriptableObjects without being version locked.
     
    Fera_KM, theANMATOR2b and Baste like this.
  6. nikolinehoegh

    nikolinehoegh

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    6
    If this is not possible, would opening the prefab in a separate view (a "prefab editor") be a substitute?

    What kind of information would you need in order to not "mess things up"? Would it help to be able to look up in which scenes or other GameObjects that a prefab is used?
     
    firejerm, Gizmoi and Martin_H like this.
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I use prefabs mostly for objects we will see a lot of in game.
    • What are you currently using prefabs for? What is your workflow for creating these prefabs?
    A bunch of stuff including (but not limited to or exclusive to) colliders, visual, sound, scripts. Typical example: an enemy I can drop in and press play and we go.
    • Are there limitations, gaps, or issues when using Prefabs in your workflow?
    Not really, no. I'm well used to how it is now, and frankly making uber-prefabs of nested stuff will just lead to poor design patterns in my view. I'll probably keep using prefabs just as they are now.
    • Are you currently using any Asset Store plug-ins for Nested Prefabs? What problems does it solve? If you wrote your own, what does it solve that others don’t?
    Nope. I'd love Unity to create a robust internal pooling system that works with Instantiate and prefabs though. Something performant.

    And I have used Unity for a long, long time and released plenty of games. The existing prefab system is not really limited unless you want to create an inheritance based approach. But, like code, I warn you that you may not like where you end up. It's a good idea to look at the pros and cons of various programming patterns as prefabs are a similar concept.

    In short, over the years a lot of people have moaned about prefabs but I think the problem is they're trying too hard to make a lot of reusable parts. In the end, when you have shipped a few titles, you realise that not a lot really gets reused and you blew a hell of a lot of waste time trying to make things so.

    Just my 2c.
     
  8. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    I have used an asset for nested prefabs, but frankly I don't think that these kinds of approaches are viable/worthwhile.

    The value in prefabs has to do with ease of use and flexibility, nesting prefabs adds so much potential complication, risk and danger to the process.


    If you want to build out nested prefabs, there needs to be very strong tools for it. You basically need all the same kind of tools you would with an IDE and type system.

    I'd think about scrapping a purely visual system and looking into some kind of markup language, like a XAML or HTML/CSS for defining object compositions. Let the visual editor come second.

    Once you allow prefab nesting, you need to really deal with references and dependencies properly, and this is a different sort of beast.

    In terms of how I currently use prefabs - after trying dozens and dozens of approaches - I currently try to keep them as absolutely minimal as possible and deal with any kind of composition/modification from code.
     
    Martin_H, theANMATOR2b and jprocha101 like this.
  9. aki-kanerva

    aki-kanerva

    Joined:
    Jan 3, 2012
    Posts:
    1,398
    • What are you currently using prefabs for? What is your workflow for creating these prefabs?
    Since scene files are notoriously impossible to merge with VCS tools and difficult to recover from error states, we use prefabs to split them into more manageable chunks. Preferably we do this in such a way that each prefab only contains one type of thing or is the responsibility of one person (eg. environment, interactive objects, HUD). This also avoids situations where, if a scene file breaks, the prefabs can still be salvaged.

    Multi-scene editing has alleviated this situation somewhat, so we have a little less need for prefabs for this purpose.

    Each of our menus is also a prefab (we use NGUI but the same applies to any GUI system).

    • Are there limitations, gaps, or issues when using Prefabs in your workflow?
    Finding the right hierarchy depth to prefabicize is always a challenge. Too high and the prefabs become massive, eliminating the benefits. Too low and we get too many prefabs for them to be useful.

    The most common issue our developers face is forgetting to hit Apply and save. With lots of prefabs in one scene, the task of checking them for modifications is time-consuming and error-prone. We've tried writing tools to automate this, but there never seems to be a good solution that would cover all use cases. It would be our holy grail if prefab names had a fourth color indicating a prefab that has modifications (as opposed to blue for prefab, gray for non-prefab, red for missing). Also a way to apply and save multiple prefabs with one click would be golden.

    • Are you currently using any Asset Store plug-ins for Nested Prefabs? What problems does it solve? If you wrote your own, what does it solve that others don’t?
    Not nested prefabs as such, but we do have things that do kind of similar things but for more specific purposes.

    We've rolled our own system for ring buffering (aka pooling) various things that need to be spawned and reused throughout the game - for example, one-shot particle effects, objects, enemies, and so on. Each spawnable object is a prefab, and the ring buffer fills up each pool at scene load by instantiating prefabs (one pool may actually contain multiple different prefabs for randomization purposes). The ring buffer itself is also a prefab so that it can be saved separately from the scene file (and reused in multiple scenes). Using this approach, we can avoid all Instantiate and Destroy calls during gameplay, eliminating GC overhead.

    We also have a system with "placeholders" for prefabs. Instead of filling a scene with prefab instances, you put placeholders that refer to a prefab (or ring buffer entry). This keeps scene file sizes manageable, and more importantly, lets us manually place lots of objects in a world or timeline while still limiting the total number via ring buffer.

    Finally, we use prefabs to reduce object permutations. Say we have 50 character types, 40 of which use the same particle effect and 10 have custom effects each. Instead of copying the same effect to the 40 similar enemies, the character prefab spawns and attaches another prefab to itself.
     
    theANMATOR2b likes this.
  10. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
    What are you currently using prefabs for? What is your workflow for creating these prefabs?

    - I try to avoid them if possible, because they can easily clutter the project. And there's no good way to find scenes referencing them, so I can't even delete them without checking all the scenes. At the end i mostly create them for reusing complex hierarchical objects. But not often for simple objects, even when they are sharing properties. In this case I just multi-edit them.

    - I create prefabs almost uniquely by dragging a gameobject from a scene into the project view.


    Are there limitations, gaps, or issues when using Prefabs in your workflow?

    - I'd love to have the possibility of saving prefabs as part of a scene. Like this I could be sure that there are no external references and it would help to reduce project-level clutter. Let's say I want to reuse a specific, not too complex object a few times in a scene. Right now I just copy it because I don't want to create a prefab for only these few objects used in one scene, because then somebody else working on the project wouldn't know what the prefab is for.

    Completely unrelated to prefabs, this workflow would also be great for Materials, (generated) meshes etc., which now always have to be saved as an the project, even when they're only needed in one scene. Right now, as projects grow, it's hard to keep track of where all the assets are used. A feature like this would allow to save these things in the place where they're actually used.

    - Another one of my issues about using prefabs: It's hard to understand modifications of prefab instances. Maybe it would be enough to just mark completely unchanged prefab instances differently, or to have a way to show a list of modifications, without having to click through all the hierarchy to check for them.

    - Also, I'd love to see ways to hide internal properties and sub-objects of prefab instances. For me the point of having a prefab of a complex object is to not think about how the object is constructed internally. So an (unchanged) instance could just hide all the internal sub-transforms and unmodified components by default, except maybe some manually selected properties and transforms. A double click on the object could show the full hierarchy like it is now.

    - It would be great to have a better way to fully edit a prefab without dragging it into the scene.


    Are you currently using any Asset Store plug-ins for Nested Prefabs? What problems does it solve? If you wrote your own, what does it solve that others don’t?

    Haven't tried any.
     
    Gizmoi, Martin_H and theANMATOR2b like this.
  11. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    You don't really need this as a "prefab". I do this all the time just by having a (generally disabled) gameobject in scene that is copied via instantiate at runtime.

    This kind of thing is really useful for GUI items for example, you want to clone a button or a list item that's only used on one screen and don't want to clutter the project.

    Another advantage is that you can place the instance (or multiple instances if you're pooling) within the layout in the editor, so you get a nice visual for what the fully populated panel should look like without having to hardcode everything.
     
  12. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    We create prefabs either b dragging from the scene. Duplicating and modifying or through editor scripts.

    For me the only thing I think of would be to have models be nested. So if the model changes the model structure updates in the prefab. But even this is not to big of a deal.
    We write lots of editor tools if we need to perform operations too often. That will regenrate the necessary nodes and behaviours.

    But in general i have pretty much worked around the nested prefabs. By just instantiating and combining them at runtime. This I think works better in general. The only thing missing is being able to override some subset of properties.

    Not using any plugins.

    The idea of a heirarchy of prefabs is interesting. Kind of how the scene file can override settings in the prefab. If a parent prefab could override its child/base in the same way. It's not technically nested prefabs but inherited prefabs?

    Having worked in unity so long my workflows have adapted now where nested prefabs are not really an issue.
     
    theANMATOR2b likes this.
  13. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    Oh this would really be useful. As any user mentioned having a better built in way to identify used prefabs and where.
    We currently have our own tool that parses all the prefab and scene files tracking meta file guids.
    This constructs a heirarchy for us for finding usages through out the project.

    We use text files and meta files so it easy to parse. Others not using these setting would be more difficult.
     
    frosted likes this.
  14. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
    I do exactly this for everything i instantiate with code, but it doesn't help in other cases. I was more talking about things created in edit mode, like building a part of a level with a few similar elements, where actual prefabs still could be useful.
     
  15. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    I used prefabs when I want to call on something multiple times. An enemy for example.

    What I would like to see is the ability to totally break the link to a prefab. Sometimes I want to make something new using multiple objects from an existing prefab, but know this is too dangerous from it breaking projects on multiple occasions (2 bugs submitted in the past), so I have to build a completely new set of objects instead, even though it takes much longer.
     
    alfish likes this.
  16. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    No need for a prefab editor or anything if its too much work. We just need to be able to refference to other multiple prefabs through.
    Like if i have a "lamp" prefab and a "ceiling" prefab i should be able to make a "room" and a "damaged room" prefab as a parent to the previous ones. So, if i change the lamp prefab individually, it will also be changed in room and damaged room accordingly.

    I use a custom editor script for this, but it is always good to have a unity solution.
     
    Rollboy0 likes this.
  17. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,332
    This is possible right now, but it's a bit of a hack:

    - Create an instance of the prefab.
    - Create a new prefab from your old one by drag-and-dropping the instance into the assets folder.
    - Now break your instance's prefab connection through the menu item.
    - Finally, delete the new prefab.

    It's really annoying that there's no built-in way to handle that, but this at least works. You can wrap it in an editor script and put it in a menu for convenience.
     
  18. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    Thank you for the suggestion, it sounds like a good idea, but I will not be using it. My bugs were related to using anything in a prefab that had previously been in another prefab, and then the project getting mixed up on what belonged to which prefab. The only solution I ever found was returning to a backup from before prefab reuse, sometimes losing me days of work. This has the potential to do the same.
     
  19. one_one

    one_one

    Joined:
    May 20, 2013
    Posts:
    621
    Prefabs consisting of other prefabs certainly do have their use, especially:

    This is really bothering me. Creating UIs would be so much more convenient if I could custom buttons, panels, headers etc. as prefabs and then also various configurations of these, i. e. certain window arrangements.
     
    Martin_H likes this.
  20. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    230
    Rodolfo-Rubens likes this.
  21. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    That depends on what advantages a dedicated prefab editor would offer me. I think I would prefer hierarchy and project folders to behave identically (in terms of drag & drop etc.), and the editing to be done in the inspector. Having yet another panel for a dedicated task seems less optimal to me. I think we already have too many different windows/tabs/panels to remember what exactly gets changend where (like settings for "player", "graphics" and "quality" - I can never remember where I switch to linear colorspace and deferred rendering, and I could swear it was changed in one of the recent version updates).

    If you want my opinion on examples to check out for complex software UIs, I would recommend zBrush as an example of how not to do it, and Reaper's options menu as an example of a perfect way of making a wealth of settings and customizability accessible to users, without needing to remember where to find everything. They've just added a text search field for their settings. You can easily type the keyword in that you're looking for, and skip through the search results till you have what you want to change. It's also great for exploring related settings that you might not even know existed in such a feature-rich tool. I also like how blender opens a search menu when you hit space that can be used to easily find and execute functions from. I think for complex software this can often be much more useful than (just) adding more windows and panels.

    Yes, such a function would be very helpful, not only for prefabs, but for all other assets as well. It would be useful to hunt for unused assets that only clutter up the project.
    I would like to have optional color coding for compound/nested prefabs, where each prefab within another prefab gets a different color, so that you can clearly see what belongs to what. And clear functions and workflows would be needed to handle things like dragging a prefab into the hierarchy of an in-scene nested prefab. Where does that get added? Just the instance? As a nested prefab of the nested prefab you've dragged it into? As a nested prefab of the topmost parent prefab of the whole compound? Can parts of nested prefabs be rearranged within the hierarchy without breaking prefab links?

    I strongly agree on the feature request posted above for clear color coding of prefabs that have local scene overrides for properties and "untouched" prefabs. I also could see value in different "scopes" of prefabs (project, scene, maybe even object hierarchy). UI stuff probably would be the most obvious application where I'd try out nested prefabs. For actual gameplay objects I think @hippocoder named some good points why nested prefabs might not work all that well in many cases.
     
    one_one, frosted and Baste like this.
  22. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    P.s.: I just checked a few things regarding the search field for project and hierarchy again and I think there really is some room for improvement. E.g.: when I search for something in the project panel I would want to have the full path where a prefab or asset is located as a mouse-over. Usecase: having something open in the inspector and wanting to drag something over there - I usually know the name, but more often than not there is more than one thing with a similar name, and only the location in the folder structure tells me which one is the right one. But currently I need to click the search result to get that information and that will make the inspector lose focus of what I was planning to drag the prefab to.
    Same goes for the hierarchy, in fact it's even worse there. Searching disables dragging completely here. I think those things always should work consistently and the search filters should just affect visibility of elements.

    I'd also like to have the little triangles, for expanding child objects, visible on search filtered objects too if they have children. I'd like to be able to type "turret", get a list of all things containting "turret" in the name, mouseover to see which turret belongs to the specific entity I'm looking for, click the triangle to expand the hierarchy and with that auto-clear the search field, automatically expand the hierarchy to reveal the children of the turret, automatically scroll the hierarchy window to keep the object I expanded the children of in view - if possible adjusted to also show all its childreng but giving priority to keeping the thing itself visible if not all children fit - but not select it and make the inspector focus on it, unless I specifically click on the object. You may ask "what has that to do with prefabs", and I'd argue "a lot", because the primary way to create, place and edit prefab is with drag & drop interaction and I would suggest to polish and optimize the hell out of those before jumping to nested prefabs, because the productivity gains from it would be more immediate, applicable to more usecases (pretty much everyone using Unity), and the nested prefab system needs to be engineered with all those possible interactions in mind. If you make the nested prefabs first and then later try to add more and better drag and drop functionality you might hit edge cases where you can't keep the behaviour consistent and intuitive, and you won't want to refactor the nested prefabs then, because that would likely break projects already using them, so you'll be forced to make bad compromises on the UI interactions. At least that's my best guess for how it could go down in a worst case scenario.

    Some of the drag&drop workflows in Unity are really good and intuitive already, but some things make me scratch my head, like why in 5.5.2f1 you still can't drag&drop reorder components on an object (like image effect stacks on cameras). I believe this is implemented in more recent versions (Thanks!), but personally I would have given something like that a much higher priority than it seemed to have.

    Thanks for listening to our feedback! I know you all are working hard and want Unity to be the best engine it can be, and I'm very grateful for that!

    Cheers
     
    one_one likes this.
  23. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,563
    I saw a notice and decided to chime in.

    One REALLY annoying thing with current prefab system is that coordinates of root transform are part of the prefab. It makes dealing with top level objects a bit inconvenient, and this kind of behavior is not what you usually want. For example, I have a projectile prefab, drop it into scene into a location where it doesn't get in the way of anything, modify visual details, press "apply", and its root coordinates are now stored in the prefab. Would be nice to somehow have this as an optional behavior.

    On somewhat related note, there needs to be some sort of flag that prevents object from being duplicated in editor. I create dynamic GameObjects with HideFlags.DoNotSave/HideAndDoNoTSave as children of an object with monobehavior that has [ExecuteInEditMode] on it, and then drop the whole system into prefab. Here's the thing, though... when I drop them into prefab, or drag a prefab into a scene, everything is fine. You get one "dynamically created" child object. However, when you start duplicating them in the scene, new objects receive copies of the original "dynamically created" child object. Meaning if you have a gameObejct with a mesh on the first object, you'll have 2 of them on the first copy, 3 on the second, and so on. Getting rid of the clones sometimes require a full scene reload.

    I believe the first time I've run into this issue was during 5.0.0 release, and even then someone mentioned that it would be nice to have a flag to prevent duplication. After all this time still no "do not duplicate this on Ctrl+D" flag. I understand that this is not strongly connected to prefab system, but it would be nice to have this fixed anyway.
     
    Aiursrage2k, alfish and Martin_H like this.
  24. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    246
    We use prefabs for UI elements, and I would love an inspector for UI prefabs, but that would be pretty complicated. There needs to be a UI canvas and our prefabs are dependent on the surrounding layout containers. So maybe also save the inspection layout properties with the prefab?
     
  25. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    Sorry I'm not going give a more in-depth answer, I don't have the time right now, but I'd very much like to see something more like what Unreal do with their Blueprints. Prefabs would be treated more like a Scene that can be Instantiated. So I can open that Prefab and view it in its own space / Scene.
     
  26. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    So a question I would like to ask here, is there any reason for prefabs to be gameobjects? Like has anyone ever had a use case where prefabs and active gameobjects being ostensibly the same was important?
     
    Martin_H likes this.
  27. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    We are using the stock prefab system because most third-party tools are clumsy and unreliable.

    The lack of nested prefab is a drastic issue with any workflow beyond simple mobile game. The moment you want to have pattern of gameplay, you're screwed. We hate the current prefab system, but we are forced to live with it.

    I've worked with a couple of in-house engine that had complete and total nesting system. By example, Anvil/Scimitar for Assassin's Creed. You can't do a game the size and complexity of Assassin's Creed without proper nesting. Unity's issue is the serialization, but more importantly; the inspector. Right now, with how the inspector is working, you will never be able to have proper nested prefabs. Never. It will always be an half-assed solution that break easily and doesn't answer half the requirement of a proper nesting system.

    The reality of a nested prefabs is that each variable need to be overridable independently, which mean each fields in the inspector needs to be aware of its context, which currently is not the case.
     
    Martin_H likes this.
  28. TurboNuke

    TurboNuke

    Joined:
    Dec 20, 2014
    Posts:
    69
    I don't really use prefabs any more, they're more trouble than they're worth for me.

    To improve matters, separate 'base' variables and 'per-instance' variables. Instance variables should never be updated by clicking Apply on other prefabs.

    Nested prefabs would be good. Flash has had that kind of system forever, and it is extremely powerful.
     
    Martin_H likes this.
  29. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    I think I actually would have good usecases for having prefabs that are collections of monobehaviours without transform. I have different building types and some of them could share essentially the same data for setup outside of mesh and collider, so a component with a slot for a non-gameobject prefab that instantiates and adds the components from the prefab at runtime, instead of having basically identical copies of these components scattered accross all building prefabs. Since afaik you can't "copy" components over at runtime without crazy workarounds, you currently can only sort of solve this by writing code that generats the components in place of using the prefab system. A nested prefab solution wouldn't really solve this if every prefab still was tied to being a dedicated gameobject.
     
  30. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    I use prefabs for monsters, bullets whatever. Everything you need multiple instances of is spawned as a prefab. Anything that can get screwed up in different scenes you want to use a prefab you dont want your ball behaving one way in 1 scene and another in another.

    You need a way of maintaining scene specific data on the prefab for example a menu might have specific data in 1 scene and different in another (although I guess its kind of trivial to change it via scripting).

    This is more about spawning a prefab and making it a child of an object, the rotation, scale can change and screw things up. I almost always want the scale of the prefab root transform to be the same size after it becomes a child. But its kind of trivial as well.
     
    Last edited: Jun 20, 2017
  31. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    I would say that's about the point where scriptableobjects and the composite pattern start to make more sense, even more so if it only needs to be read only and can have a shared single instance.
     
    Martin_H likes this.
  32. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Neither of that is the case for what I need, but I need to read up more on scriptable objects some time anyway. Their concept hasn't fully clicked for me yet. If you happen to have something other than official docs and superpigs unite talk that you'd recommend, let me know.
     
  33. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Actually, composition pattern is "supported" in Unity... even if not explicitly. It's some of the features of Advanced Inspector, but honestly I would prefer something "native".

    But it comes back to Unity's inspector in desperate need of a MAJOR rewrite. Almost any more advanced feature would rely on massive change on how data is handled and exposed.
     
  34. forthex

    forthex

    Joined:
    Jun 23, 2017
    Posts:
    3
    arewenestedprefabsyet.com

    ****posting aside, I'd really appreciate nested prefabs for UI. I'd love to see something like React JS in Unity, and I believe it can be achieved with nested prefabs.
     
    Martin_H likes this.
  35. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,466
    • What are you currently using prefabs for? What is your workflow for creating these prefabs?
    As I am an artist on my dev team, I use Prefabs to allow me to easily create assemblies of objects that I will frequently use in my levels, example a light fixture that I will create tens of times. I also use Prefabs to create different versions of characters that may have different traits such as bigger armour or missing a limb for dismemberment.
    • Are there limitations, gaps, or issues when using Prefabs in your workflow?
    The only limitation I can see presently in that Prefabs do not save lighting information when I use Enlighten or the PL in standalone builds or tests. It constantly bothers me that we have to use a script to fix this limitation when it should just work correctly the first time. I'm not a programmer and I don't have that kind of time to be mucking around looking to get my lightmaps working. It would be nice to be able to bake lightmaps (whether it's set to realtime which I prefer or not) to the prefabs especially since they are set to static, and call it a day. My current workflow for prefabs, is to bake down the lights in Baked mode (Mixed mode leaves undesired results), and after it is done, Unhide the realtime light, and set the PL to realtime GI (it shouldn't overwrite my baked maps.) for characters.

    Also, the script negates your ETA system...
    • Are you currently using any Asset Store plug-ins for Nested Prefabs? What problems does it solve? If you wrote your own, what does it solve that others don’t?
    No.
     
    Last edited: Jun 23, 2017
  36. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    We use prefabs for almost everything in our game. Our scene (we only have one) is very sparse, having only a UI root with a splash screen, and a few game objects with scripts attached (our bootstrap script, HockeyApp, an in-game console, etc.). Everything that drives our game is created and initialized by a content system that loads prefabs from either the Resources folder (we generally stick our UI prefabs in here) or AssetBundles (for characters, monsters, etc.).

    We create our prefabs by crafting the game object in the editor (or duplicating an existing prefab, in the case of UIs where we want consistency across screens) and saving them back to our project view. Every time we need to update a prefab, we drag it into the hierarchy, do our edits, make sure we apply them (usually), and delete the prefab in the scene.

    A number of issues have come up through this flow:
    • We try to keep common UI elements consistent across our UIs (e.g., controls, like buttons, and window treatments). If we update the look and feel of a button in one UI, we currently need to make sure it gets updated across ~25 different screens, and we invariably forget one (or more), since they're baked within each UI prefab instead of just being, say, a "button" prefab we can nest within each UI.
    • Sometimes we have horizontal/vertical list views with separate "list entry" prefabs we spawn into those views. During testing, we drag these list entry prefabs into their view container to check layout and functionality. However, we routinely forget to delete these prefabs before we hit apply on the container UI, so we end up baking the entry prefab into the container. It's never been an issue where we've gone live with an errant entry, but because these entries need to be initialized through code (e.g., we might pull player objects from our server and use them to populate the list entry prefabs' data), we'll get an error at runtime because the baked entry is not initialized. I'm not entirely sure how to solve this, but I wanted to bring it up as something that's a tad annoying with our current workflow (i.e., making sure to "clean up" a prefab with nested list entries before we save it).
    • Because everything is a prefab, we are forced to do a two-step process in code to initialize them. For example, we'll do a Resources.Load<MyUIScript>() on a UI, then we need to call an Init() method on the MyUIScript (or whatever) component attached to that prefab to pass it relevant data. This is just something we've accepted, but I'd love to be able to combine these steps, since they're clunky. It also makes us have to reason about the order of operations, since we're not conforming to the Awake()/Start() behavior of MonoBehaviours (well, we are, but we do it in addition to our Init() methods). I always have to think about when the Unity event methods run in relation to our own Init() method and it's caused us issues in the past.
    We've thought about using nested prefab plugins, but ultimately we don't want to complicate our code any more than it already is, and relying on external systems seems less than ideal.
     
  37. goran_okomotive

    goran_okomotive

    Joined:
    Apr 26, 2017
    Posts:
    60
    Would be great if we could mark a serialized field in a MonoBehaviour with an attribute, which would prevent the field from being overwritten by a prefab. Right now it's impossible to have a unique identifier for a prefab instance in the scene, since every field gets overwritten to the prefab assets value by pressing the revert button.

    This could be super helpful for a save game system f.e. When loading data from a file, we could identify and use existing prefab instances in the scene and populate them with data. Instead the common workflow right now is to first delete all existing prefab instances in the scene and then to instantiate new ones and to populate them.
     
  38. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    • Are there limitations, gaps, or issues when using Prefabs in your workflow?
    there are things aside what members already stated, for example .. looking at prefabs in Project folders.. if parent gameobject does not have a mesh renderer...it will be shown as blank image box.. i have many prefabs which contains mesh renderer in child gameobjects.. but they aren't represented in the prefab image.. it will be more convenient if there is away to represent child mesh renderer in the prefab view in project folder..or in other words.. show an image as same as if it was placed in a scene (show all child objects meshes)..

    it would be awesome as well if it shows particle systems.. for example if i made a prefabs for different explosions using particle effects.. it would be nice to see the image for each prefab..(if particles have play on awake set)
    it really feels awkward navigating project folder for prefab effects that i can't see unless i place it in scene..


    in regard of prefab and scenes... i found it common that applying some edits..
    effects prefabs and in turn it might effects prefabs in other scenes..that might cause problems and extra work and wasted time etc.. we need some level of control on prefabs when applying updates.. and let developer choses how these new updates applied on prefab/instances/scenes etc

    my suggestion for this.. if i made prefab larger in a scene and added different material.. when i hit apply the editor should asks me where to apply these updates as an example for options i find useful:

    - Source & All Instances : applies updates on source prefab + other scenes + current scene
    - Source Prefab Only : effects prefab but not any instances on any scene in project..retaining whatever component they have..
    - Current Scene Only : Only updates prefab instances on current scene only.. not modifying source of any instances on other scenes..

    -Add Only : update source and all instances in all scene.. by adding new components added to the prefab.. without removing any existing component or values..
    for example during project.. i might want to add a box or sphere collider for tree as a new child game object.. without touching any other edits made per instance in all scenes.. its just a small update.. i do not want from this small update losing all little details and edits made per scene or instance..

    in that sense..
    i feel it is better if scripts and component fields shows values in blue text (indicating values that are from source prefab).. and show orange text for values shared or applied in scene... and then black text for unique edits on single instance..
     
    Last edited: Jul 1, 2017
  39. Wahooney

    Wahooney

    Joined:
    Mar 8, 2010
    Posts:
    281
    Besides nested prefabs (nested prefabs).

    A method of flagging fields as only editable on prefabs (not prefab instances) would benefit useful.

    Nested prefabs.

    On the opposite end, an attribute for fields that don't get applied back to their prefab when you Apply the prefab.

    Nested prefabs.

    I've needed both of those attributes a crazy amount of times in the past few months, so yeah, that's my 2 cents.

    Nested prefabs.
     
    makeshiftwings likes this.
  40. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Another use for prefabs is to have an abstraction for models that you use. Most of the times you dont want to use the model directly but want to add some scripts instead, however if you change the model the scripts dissapear.

    https://www.assetstore.unity3d.com/en/#!/content/199

    This asset solves that problem, but maybe something built in from Unity would be preferable.
     
  41. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    254
    These two things doesn't work simultaneously, which might be a common use case.
    1. Creating a menu as a prefab
    2. Creating any gui item in that menu as a prefab
    These are workarounds that comes to my mind.
    1. Your menu has to be a scene, and are therefore subject to scene-as-a-gameobject bugs, overhead etc.
      or
    2. Gui items have to be managed without prefabs
    I would love to have nested scenes too.
    It's so close now that we can open multiple scenes at the same time.
     
  42. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    230
    Last edited: Jun 26, 2017
  43. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Can you please tell us a bit about what impact, if any, this thread had on your plans for nested prefabs?
     
  44. eatsleepindie

    eatsleepindie

    Joined:
    Aug 3, 2012
    Posts:
    355
    My biggest complaint with prefabs is in that, regardless of my experience with Unity, making changes to one rarely leaves me feeling confident about the outcome, and sometimes the consequences can be incredibly time-consuming to remedy.

    I use prefabs for just about anything that is going to be used more than once. Personally I think that prefabs should be their own 'system' in and of itself. It needs more depth than can be offered via the hierarchy panel and maintaining those prefab connections is paramount - something I always assumed but unfortunately experienced in a recent project as it approached release. We had to revert to a commit from two weeks previous when we realized that at some point every single prefab connection (most buried deep in the hierarchy) in the main scene inexplicably had gotten lost. 'Revert' was not an option as it reverted nearly every value (as several people have already mentioned), and even if it was we cannot revert multiple instances all at once, we would have had to do so for every single one individually.

    Prefabs are so important, especially to smaller studios/solo developers in that they save a lot of time when used correctly. Yes, a panel in which I can drill down through all the children in a prefab would be great, but more would be better. The ability to see/edit a prefab without dragging it to the scene at all would be a great improvement to workflow, especially in the case of those using UI elements or mesh renderers on child objects.

    I know it is a lot to ask for, but a separate panel and system in which I can not only edit a prefab, but create sub-prefabs(?) of that prefab where I can easily 'lock' certain values to the original while adjusting others would be a massive time-saver for my workflow. Changes to the original would then change any of the 'locked' values of any of the sub-prefabs created from it, allowing me to quickly create multiple versions of a single prefab, each with some unique settings/children, all tied to the original for a streamlined workflow. The only other option really is to instantiate prefabs inside of other prefabs inside of other prefabs, which feels clunky, is difficult to edit and if you're not careful can result in broken connections; that or have 10 different versions of the same prefab and edit them all every single time you want to make a small change.

    To further my point, consider the following: I spend hours upon hours in my prototype/concept project building the UI, using prefabs whenever I can but ensuring I maintain connections and also that I do not accidentally overwrite a prefab setup by applying changes when one if its child objects is a prefab itself. I am using the default UI elements Unity includes because I am not sure this idea will pan out; best to get the core system setup and tested before I run to the Asset Store and find a UI skin I like. Once I purchase that skin, the real work begins, as I am having to go through every single UI prefab I have created to make the same change over and over again; be it a background graphic, my toggles, etc. The only way to do this is to drag it into the scene, make changes, apply and hope for the desired results. If every in-game UI panel was a "sub-prefab" of an original panel, it's now a one-step process. If every toggle was the same nested toggle prefab that maintained connections properly, updating that is now a one-step process. The list goes on and on, and we all work with major time constraints, be they from only being able to dev in what short amounts of free time we have or those of us with release dates hanging over our heads.
     
    TurboNuke likes this.
  45. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,320
    Welcome new prefab team!

    I use prefab for everything that gets instantiated by code, and even for bits of the environment. I use them as a way to work iteratively starting with blocks and rough geometry or zero code and work my way up to something that feels good. Workflow used to be keeping a separate scene with all the prefab bit in not blue-but-linked state but now I just work from a level scene to see colors and sizes and do a quick test. Hierarchy of my prefabs is always root-nodes-maya asset so I can swap asset and keep the logic intact. Usually I create the root in the following way that's convoluted to copy the asset's SRT : I drop the asset in the scene then select that asset then right click create empty game object, which creates an empty GO in the same SRT as the asset, then detach that and rename it to name of asset but capitalized, then parent the asset under it and start populating that root with components. Then I drag and drop that proto in the project view, done - first prefab. Then I iterate either in the scene view or directly in the project panel, adding component to the prefab, linking stuff or changing values.

    Once prefabed, the asset loses link to the original so any change of hierarchy in Maya gets lost in the prefab. Also if you add a prefab inside another prefab, once you apply that addition the sub prefab gets flattened and loses the changes that are done to the original after that (zero nesting).

    I use Nested Prefabs which makes working a breath. Assets keep their link so when I change a model hierarchy in Maya it'll update all the prefabs. Also if an enemy has a few laser canon and I change the geometry, or add a few colliders to the laser canon prefabs, the enemy stays up to date.

    PS: sorry if some of this doesn't make sense, I left autocorrect on by mistake :p
     
  46. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    laurentlavigne likes this.
  47. Deleted User

    Deleted User

    Guest

    maybe itd be cool if there was an ability to add a little icon visible in the Prefabs,
    itd make looking through asset folders more at-a-glance


    .. hmm you can add icons to stuff in the scene view but not in the Prefabs or in the Hierarchy? or do i just not know how??
    the icons show up in the Scene and Inspector, and fields in the Inspector, but not in the Hierarchy or Project/Prefabs/Assets window ??

    - itd be nice for like empties i just use as a "Folder" parent to organize the hierarchy better
    - and for empties that just act as a quick transform origin point alteration.

    - and yeah you could add like a sword symbol and stuff like that


    ive been just naming those "Folders" with "f_" ... f_Canvases for example


    and i guess theres some solutions like that on the asset store though...
     
    Last edited by a moderator: Jul 2, 2017
  48. nikolinehoegh

    nikolinehoegh

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    6
    We are working on something for this. Complexity question: How complex do you see these variant structures becoming? If Prefab B inherits from A, would you then want a C which inherits from both? How about branching, so that C & D both inherit from B?

    How do you see this prefab window working? Would it resemble a scene with the ability to set up an environment, or would it be more like a preview window? Unfortunately, folding out prefabs more than 1 level in the Project is not an easy fix. We are currently looking into other solutions..

    Thanks for the feedback! We are going to update this thread with more info soon.
     
  49. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    My game is mostly procedurally generated so I use prefabs for almost everything. The workflow is to build the object in a scene and then drag it to a folder to create a prefab... is there some other way that I don't know about? If there is I'd love to hear about it.

    Obviously the lack of nested prefabs is a huge limitation. In one project I wrote my own sort-of-nested hack that would let the UI designers do things like change the font on all the buttons even if those buttons were within prefabs, but it was a pain, and it would have made my life a million times easier if there could have just been a "button" prefab that they could change that would propagate out to every other prefab.

    Another obvious one that people have been complaining about for years is that you can only edit one level deep in the project menu, meaning you always have to drag a prefab into a scene, change it, apply, delete... seems like a bunch of unnecessary steps for no reason.

    In my current project, I save most of the game data (item stats, enemy stats, quests, etc) as json files in a database (for lots of reasons, not just to avoid prefabs), and I limit the amount of data stored in prefabs. This way I can be sure that if I change values in the base data, it will be properly propagated to any instances in any scenes regardless of how they are "nested".

    I used PrefabEvolution for a while but eventually deleted it because it seemed very buggy, sometimes I would lose all the nested links for no apparent reason, and the fact that I had to constantly worry and double-check on anything nested just led to me not ever nesting anything anyway, so I stopped using it.

    I feel like examples are everywhere. Unity is based entirely on a component-based design, so everyone's natural inclination is to think they can use a component-based design with their prefabs, but you can't. Examples: Making an enemy prefab holding a sword prefab and a shield prefab, but being able to alter values in the sword and shield. Or making a UI prefab of a window that contains a button prefab, but being able to alter the looks of the button.
     
    Last edited: Jul 19, 2017
  50. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    Some things that would make it easier.

    1) Have a separate editor window to edit prefabs instead of having to drag them into a scene. (This would basically be like a scene window with a simple light and camera and the camera focused on the prefab. And the prefab changes depending on what is highlighted in the project explorer).
    2) Nested prefabs would be nice. e.g. you have a lot of monster prefabs that all have the same eyes. And you could then just edit the eye prefabs.
    3) In the library it only shows one level down in the object structure of the prefab.
    4) Maybe all prefabs should automatically become resources so you can load them by name.
     
    Last edited: Jul 20, 2017
    joshcamas likes this.