Search Unity

[Official] Prefab Improvements

Discussion in 'General Discussion' started by bibbinator, Jun 23, 2014.

Thread Status:
Not open for further replies.
  1. dustinandrew

    dustinandrew

    Joined:
    Apr 30, 2010
    Posts:
    102
    Who are you?
    Full time interactive developer working on kiosks, exhibits, mobile apps. Part time indie game developer @MadRuseGames

    What kind of game are you trying to build or would like to build?
    Currently working on two games. Subaqueous, a casual underwater exploratory puzzle game http://dustinandrew.me/wip/#/subaqueous/ and Knight's Temper, a RPG adventure game http://dustinandrew.me/wip/#/knights-temper/

    How do prefabs fit into that? What use-cases do you have?

    In Subaqueous, everything is a prefab, each type of block, treasure, enemy, etc. We built a level builder that allows us to layout out and build levels using these prefabs. Each prefab has a specific class that can be adjusted. So for example each instance of a certain enemy can have different settings like agro range, attack damage, speed, etc... This works good because if we need to adjust something across the board, we change the prefab and all the instances update, as long as that property hasn't been changed.

    What about the current prefab system isn't working for you?

    As I stated above, if we need to make a change to all instances of a prefab we can, as long as those instances have not change their own values. I would love to see some option from the prefab, not just from each instance, to apply a change to all instances and override their values, per property.

    This would be helpful if say I had 200 instances of an enemy prefab over 30 levels and need to reset a property.

    Also, nested prefabs please. Coming from 15 years+ of Flash/Flex development this is something that I got very use to, a MovieClip within a MovieClip. GameObjects should be able to be connected to a prefab OR connected to the first parent that is connected to a prefab.

    This would be useful if say I had a gun prefab nested in several enemy prefabs and needed to adjust something on the gun prefab.

    Also, imported meshes should auto update when inside a prefab if the mesh is reimported with changes.
     
    Last edited: Apr 26, 2016
  2. emiller100

    emiller100

    Joined:
    Jul 17, 2010
    Posts:
    39
    Who are you?
    I am a hobbyist trying to go commercial. I work in IT for my day job as a DBA.

    What kind of game are you trying to build or would like to build?
    3rd person arena fighting game, Mario kart like game, endless runner game. I have many concept and prototypes that I have been playing with.

    How do prefabs fit into that? What use-cases do you have?
    My main gripe is trying to create a prefab that has a prefab as a child gameobject. Changing the child prefab in the assets folder does not change it in the parent prefab in my scene. In one of my prototypes I have a row prefab that is made of blocks that are each prefabs. Editing the individual block prefabs in my assets folder does not change the row prefabs children so I have to have a special scene to edit the row prefabs. This is very time consuming since I only have 5 blocks but in many different combinations for the rows. It would b nice to be able to change a block and have the 50+ rows that have that block also change.

    What about the current prefab system isn't working for you?
    Nested prefabs as I have explained in the previous question.

    I do have a suggestion that would be a really nice feature. I have seen this done in some of the IT tools I use as a DBA. Currently prefabs show properties that have been overridden in the inspector as bold. You can revert the whole prefab to the original which is nice but it would be even better if you could revert each individual property independently. If you could add this and allow changes to the prefabs in the assets folder propogate to the parent prefabs that would be great. Also if the property is overridden it should not be changed by changing the prefab in the asset's folder.

    Thanks!
     
  3. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    969
    ^ What he said, Unity should hire this guy :p

    I was there at the Unite presentation, and when I saw it, I thought it looked like exactly what I wanted, and it looked as good as done, so I was hoping to get to play with it within a few months. Instead there's been two years of nothing.

    I'm guessing Epic was there as well, because it looks a lot like what blueprints are in UE4.
     
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,325
    Agreed, currently it's a source of problem but I think the idea of packaging meshes inside prefabs is elegant and it will pay off once nested prefab work.
     
  5. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    *Who are you?*
    Simon Dean, Project Lead, Folk Tale @GamesFoundry

    *What kind of game are you trying to build or would like to build?*
    Sandbox Citybuilder RPG [Win, Mac, Linux]

    *How do prefabs fit into that? What use-cases do you have?*
    Our use cases echo those outlined by hippocoder. To be able to create new prefabs from existing prefabs and new meshes, and have sub-edits ripple up the nesting chain while respecting any overrides.

    *What about the current prefab system isn't working for you?*
    Our asset pipeline has since become automated and has bypassed our original issue with prefabs. Prior to that we had to setup a 'prefab of prefabs' hierarchy in a library scene, and then duplicate it before making them into project prefabs. That was the only way we could retain the original structure and child-prefab references and ripple updates.

    As someone above highlighted, 'Apply' is one of the problem areas.

    PS. Very much looking forward to Unity 5.0. So many systems that in their own right would make the upgrade worth it for us ( FMOD integration rewrite, Enlighten etc. ).
     
    Last edited: Jun 29, 2014
  6. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Can you please do a mock up of this one? I am not sure I quite follow what is you would like to have.
     
  7. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,553
    Oh and I forgot, it would be nice if instantiating prefabs came with a built-in pool manager.
     
  8. ToreTank

    ToreTank

    Joined:
    Jun 23, 2008
    Posts:
    165
    Who are you?

    Trond Abusdal, programmer at Rock Pocket Games ( www.rockpocketgames.com )

    What kind of game are you trying to build or would like to build?

    We're building games for different platforms - mobile, pc and console. It ranges from small educational and advergames to puzzle and adventure platformers.

    How do prefabs fit into that? What use-cases do you have?

    We're using prefabs for most reusable stuff (building blocks, players, environment) in our scenes. Nested prefabs would significantly decrease the pain it involves to update models or other sub-components that are frequently used within prefabs. We often resort to keeping a script reference to other prefabs and instantiate those at runtime. The downside to this is that it's somewhat cumbersome to see the whole prefab in its entirety at once in the editor for configuration etc.

    What about the current prefab system isn't working for you?

    • It is too easy to accidentally make changes to prefab instances in the scene that go by unnoticed.
    • Prefab instances cause a lot of noise in the Hierarchy, as they are fully listed with all their children etc.
    • Editing prefabs is cumbersome, as you have to drag them into your scene and do the Apply-workflow for any node that is not an immediate child of the prefab. This also has the side-effect of unnecessarily flagging the scene as "changed".
    • The missing support for nested prefabs makes it cumbersome to compose complex gameobjects and make changes to frequently used shared sub-objects.
    • Apply doesn't automatically flush a prefab to disk.
    • When a scene is saved, it causes all the prefab instances to be dumped into the scene file in their entirety. This has two major problems:
    1. It's causing *a lot* of noise in scene diffs. This is particularly annoying when a very simple change has been made (for example a checkbox change), but some prefabs have been changed since the last time the scene was saved and suddenly they are re-written to the scene file.
    2. Text-scene files quickly get unmanageable for merging or manual inspection as every prefab instance that could be represented as a position and a guid, for example, is fully contained in the file.
    At last I just wanted to repeat what someone else pointed out before in this thread, that the prefab system that Nicholas Francis demonstrated during Unity '12 looked pretty awesome, and as far as I can tell would alleviate most, if not all, problems that we are experiencing with prefabs.

    Nicholas also has a pretty neat custom solution described at http://framebunker.com/blog/poor-mans-nested-prefabs/ , but making it work well with navigation meshes and especially light-baking poses some issues that seem non-trivial.

    -Trond
     
  9. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Who are you?
    Gameplay/tool programmer at Swing Swing Submarine.
    Previously gameplay programmer on Rayman Origins & Rayman Legends at Ubisoft, part of the core team working on the UbiArt framework.
    Currently in pre-production of Seasons After Fall with at least one year of production ahead of us (team of 5).

    What kind of game are you trying to build or would like to build?
    Modern 2D game: flat 2D rendered in perspective 3D, 2D gameplay, organic feel, no square tiles, no pixel art.
    Technically similar to what we did on Rayman, but the gameplay will be much slower (exploration/puzzle rather than hectic platforming).

    How do prefabs fit into that? What use-cases do you have?
    We have a lot of animated characters, with complex animation rigs. At the moment the rig is done in-Unity, in a dedicated scene (see this post for details). Many of the rig parts are dynamically instantiated prefabs.
    When a programmer integrates this rig, he adds a few "AI" scripts, maybe some triggers etc as child objects, and puts this into a prefab that a level designer can reuse... which as we know breaks the connections to the animation part prefabs, or any other sub-system that we might want to include (FX, etc).
    So right now we drag'n'drop to the prefab but don't save the scene: the rigging scene kind of acts as a nested prefab, in a very, very inconvenient way.
    Sure some stuff could be spawned at runtime, but not seeing exactly what's inside a gameplay element makes edit-time all the worse (not to mention the performance cost of spawning).

    What about the current prefab system isn't working for you?

    The Apply button is a (bad) joke. We never ever use it. Unity support massive per-instance changes (added/removed components, added children): apply merges everything destructively. We need way way more granularity: context menu at all levels: individual gameobject / component / inspector field: all have "revert from prefab", all need "apply to prefab".

    What I call nested prefab, and would love to have:
    • have a prefab "body part" (basically a GO with a SpriteRenderer and added stuff)
    • an animator creates an animation rig made of a bunch of body parts, puts this in an animation prefab
    • a GPP creates an AI rig that includes the animation rig and other stuff, put this in an LD prefab
    • if we change the basic body part prefab, all animation rigs inherit from the change
    • if the animator changes an animation prefab, the LD prefab inherits from the change without needing a GPP to re-rig anything
    If I had to choose, I would settle for not being able to modify fields inside of nested instances, but the very minimum I want is to be able to "spawn" a child prefab inside of a hierarchy and have the parent stuff be able to reference child stuff.


    In complete contradiction to that :), I would love to have prefab inheritance
    • "white prefab"
      • "blue prefab"
      • "red prefab"
    Ideally "white prefab" could be marked abstract so that LDs cannot instantiate it.


    I'd also love the ability to compose prefabs, eg have components floating around inside a non-GameObject prefab, then have a "real" prefab include a bunch of prefab-components. Example:
    • BadGuy prefab with only an FxBank component, with stuff like dieSound = "die.wav", rewardSound = "yay.wav", etc.
    • Minion prefab, with its visual and everything, plus include the BadGuy component
    • Boss prefab: same thing
    This way if I change the FxBank prefab, all enemies inherit from it.
    Sure with nesting the FxBank could be in a child GO, but sometimes it's better to have components side-by-side.
    Right now we do this kind of stuff with ScriptableObjects, but this means you have to anticipate the data structure at the time you code the components, which can be an arbitrary choice, not as data-driven as it could be.

    Another way to look at this is "presets for anything", eg being able to extend the preset system that the color and animation curves use --> add an FxBank component --> context menu --> "use values from preset BadGuy" (again, granularity: per-field / group of field / component).
    Others have said it but UI is a great example: NGUI without a stylesheet is a joke! Even if you have prefabs for everything, you soon end up with "small button", "medium button", "big button", and dozens more, and now you want to change the colors... joy. From what I've seen in the beta uGUI is headed in the same direction sadly...

    BTW, we had more or less all of these features (inheritance, component composition) in UbiArt because the prefabs were made of data-only LUA files. In a data-heavy game, this is immensely powerful... although just about impossible to edit: how do you collect from multiple files, centralize it in an inspector, then save back to the proper location while keeping overridden values where they should be? If you guys can tackle that, it'd be quite an achievement!
    So all was done by hand in Notepad++, yet more often than not the benefits did outweigh the pain.


    Having a prefab-rigging window sure seems nice, although coming up with a generic setup window might be unattainable. Complex rigs are often tied to custom setup-only objects, like a reference visual or a background image for a character, or a test scene for a gameplay element, so maybe a prefab could be associated with a custom rigging scene, and when we're in any scene, we select an instance, hit edit and have the rigging scene in a separate window without leaving the current scene. That would be just insanely useful!


    One last thing that's been bugging me for years, is when you want to parse the whole project (eg you're refactoring some data), you have to handle prefabs and scenes differently, and scenes have to be opened, which can lead to all kinds of surprises. When you think about it, there is no difference! it's all GameObjects & components.
    If you make nested prefabs right, there should be no difference between scenes and prefabs (from a data POV). Which means, a level could be made of a few prefabs, or sub-scenes, so you could have for example an level-design part, and a level-art part, and a level could be edited by several persons at once, each only touching stuff in their dedicated part. The container scene stays unchanged, only one sub-scene/prefab is changed by each person.
     
  10. Shinzironine

    Shinzironine

    Joined:
    Nov 30, 2013
    Posts:
    32
    Who are you?

    Developer at AlternativaPlatform (http://alternativaplatform.com/en/)

    What kind of game are you trying to build or would like to build?

    MMO third-person action

    How do prefabs fit into that? What use-cases do you have?

    The same as mentioned above - ease of level editing and construction of GUI.

    We have our own implementation of NestedPrefabs which is able to reconstruct the whole hierarchy of associated objects. Although our implementation covers most of our needs, we think that the native one will be more convinient because of natural integration into Unity’s infrastructure.

    What about the current prefab system isn't working for you?

    Aside from nested prefabs I want to mention that there is currently no support for serialization of polymorphic data on components. For example Unity won’t be able to serialize the field marked as ISomeData even if the object associated with this interface is serializable. This is a pretty subtle point, but we’ve run into this issue and for some complex cases it could be quite useful.
     
    Last edited: Jul 2, 2014
  11. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Ok, I have an issue wth Revert To Prefab. I just tested, it will revert all local changes back to prefab values, losing local modifications. It might be dejavu but I remember there was once this was not the behavior. The revert will keep local modifications.

    Say I make a monster prefab, and placed them in the scene. I modified the instances with a different health. Somehow along the line, changes are made to the prefab (skinned model changes which breaks, see my above post), and the prefab gets broken and I'm forced to revert the prefab. Any local changes I have made are lost. In the U3 time, which there are a lot of disconnect prefabs, I think the local changes are kept. I can't remember when this has changed.

    What I noticed (last time I checked) from the scene file is it is storing the whole prefab data in the scene. You could just store the uuid of the prefab, and local modifications only. That way, changes to prefab won't break, and when I want to revert, it is my choice, and not because of some broken prefab

    So it would be good to revert the prefab without losing local changes, just to replace the stuff that did not changed.

    Also this would be cool

    http://feedback.unity3d.com/suggestions/apply-value-to-prefab
     
  12. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Hi all,

    Thank you all for the feedback so far. I have been following silently most of the time and taking notes. Below is a list of what I have read so far, a lot of what has been said here is nested prefabs just using different words and use cases but essentially the same thing, but if you still feel that your specific use case is not covered by the below, just follow up with more comments.

    • Nested prefabs
      • Allow property modifications to apply to nested prefab
      • Property exposing and hiding of hierarchy and other properties (Facade pattern)
      • Clear distinction between prefab parent and nested prefab in hierarchy window
    • Derived prefabs
      • Create new prefabs from exiting prefabs and apply modifications
    • Modifying of prefab template (Think edit button on the template)
      • Consider getting rid of the Apply button, which would make editing the prefab template the only option
      • Consider apply single property change to prefab (This would not be done if we go down the path above)
      • Save immediately when done editing, don't delay it
    • Others
      • Colors of prefab object in hierarchy window is hard to see on in dark skin
      • Dragging prefabs across editors windows can have unexpected behaviour
      • Storing of lightmaps, navmesh and others in prefabs to create building blocks for e.g. a dynamic dungeon crawler
     
  13. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    This is a serialization issue not a prefab issue. A blog post was posted about the serialization just recently: http://blogs.unity3d.com/2014/06/24/serialization-in-unity/
     
  14. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    This has been changed in 5.0 all the objects of a prefab are no longer stored in the scene, unless they are referenced by something else in which case we write a simple version of the object that just contains the ID.

    The result is of course much nicer scene files when using text serialization and hopefully a lot less merge conflict when multiple people have been editing the same scene.
     
    knunery likes this.
  15. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,655
    This sounds kinda dubious to me because often I need to tune a prefab 'in context' - i.e. I need to drop it into a test scene with other bits of setup in order to check if its values are giving the right result. So if you're going to do this then you need to ensure it's not solely through isolating the prefab in a blank scene (i.e. don't do it like how Mecanim Humanoid avatars are configured).

    That said there are certainly times when it would be nice to be able to open up a prefab as if it were a micro-scene of its own - so I can find different parts of it by clicking on it in a scene view, rather than having to browse the hierarchy directly. And, of course, browsing the hierarchy directly doesn't work at all when the prefab has more than two levels of depth...

    To add to that: It's not always easy to tell at a glance whether I'm editing a prefab or an instance - the only visual cue, really, is whether the Apply/Revert buttons are shown at the top of the inspector. It'd be helpful if you had a bigger visual change when looking at a prefab in the Inspector - for example, tinting the whole background of the Inspector a different color ('prefab blue' to match the blue used in the hierarchy window, perhaps?) - so that it's harder to mistake one for the other.

    One thing that might be a lighter-weight option than prefabs in some cases: fix the 'preset' system to be what it should have been from the beginning, which is a way to define project-wide named values that are live-linked to serialized properties:
    • I create a 'Fast Enemy Speed' float preset with a value of 5.0
    • I select a bunch of instances of my enemies and set their NavMeshAgent.speed field to use the 'Fast Enemy Speed' preset
    • On entering playmode / at build time, these presets are baked in as values (i.e. the enemies start as if I'd just set 5.0 in the inspector)
    • Later I edit the preset and change its value to 6.0
    • All the instances I set to use the preset also update to use NavMeshAgent.speed = 6.0 at startup
    I see presets vs prefabs as being a bit like composition vs inheritance - using a preset value is expressing "has-a Fast Enemy Speed" while being an instance of a prefab is expressing "is-a Enemy" sort of thing.
     
    angrypenguin likes this.
  16. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,553
    Perhaps it is time to pick some standard nomenclature between a prefab in the project tab, and prefabs in the scene.

    Like "Prefab Instance", and @SteenLund uses "Prefab Template", while I got the habit of calling it "Prefab Master Copy". If UT chooses standard parlance for these things, we can explain things a little easier, here in the forums, and in the documentation.


    @superpig: I certainly would like to keep the current way of doing things, as it helps me establish scale (I want my explosion particle effect prefabs to be in the right size). Just that we'd like to have an additional way of editing it when we don't need to put it on the scene anymore. Because sometimes, the scene I am working on has a long list of objects, and having put the prefab on the scene, I'd spend needless time searching for it in the hierarchy list, when I just wanted to tweak a variable or two on the prefab, or preview the particle effects (you have to put it in the scene to see the particle effects played! I hope in the future, the preview area can play particle effects too).

    This too, is there anything impeding this to getting fixed?

    Regarding presets: That sounds to me like named constants, and it isn't actually that bad. I bet it'll help make things more readable. We're getting OT here, but if I really wanted composition, I'd ask for better support for C# interfaces, like how the plugin Full Inspector 2 does it.

    I more or less do named constants already by having them as additional variables, but that means I'm allocating extra memory for something that should be "static" in a sense. As in, following the example, my script has the "Fast Enemy Speed" variable (which is expected to not change while the game is playing) and "Current Enemy Speed" (which is the one actually used). If I made that variable static, I lose the ease of editing it from the Inspector.
     
    Last edited: Jul 3, 2014
  17. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,655
    Yes, for sure - I'd quite like to be able to double-click a prefab and have it open up a window with scene+hierarchy+inspector showing me a 'micro-scene' that is just that prefab, for me to make some edits and then close it again. Bit like editing MovieClip objects in Flash, or the prefab editing that I believe was shown in Nich's GUI videos at Unite a couple of years ago...

    Yeah, I do this using ScriptableObject to define 'templates' (so all fast enemies have a reference to the same 'fast enemy' template which has the values in) - then I can edit the ScriptableObject in the inspector. But still, this is an architectural decision in my code and affects the way I implement things; presumably the Preset system exists largely because Unity needed a solution that would work for non-coders.

    (tangential request: it'd be helpful if we could tag ScriptableObject types with [CanCreateAsAsset] and have them be added to the Assets/Create menu automatically. It's a bit of a pain having to teach someone how to set up an entire editor class just so that they can create an instance of the class they've defined).
     
  18. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Just had a thought what if Unity added a Socket state/type on an empty transform, in effect it would act as a break between prefabs. Allowing users to designate how the prefabs fit together and all the lower level prefab needs to remember is what prefab goes on the socket.
     
  19. ToreTank

    ToreTank

    Joined:
    Jun 23, 2008
    Posts:
    165
    That's music to my ears! Thanks for getting around to fixing this.
     
    knunery likes this.
  20. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    I do that kind of thing in code all the time, though I've never exposed it to an editor, which is a great idea.

    With that in mind, it actually addresses use cases that prefabs do not, e.g.: where a Prefab lets you configure a type of enemy, a synchronised value helps you ensure that certain values match across all types of enemy - this is something that prefabs don't (and should not) address at all.
     
    knunery likes this.
  21. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,553
    To be honest I've been burned by this a lot, that I've made a little editor script that lets me save both the scene and the project at the same time. I gave it the hotkey Alt + Shift + S.

    Sure it takes longer when doing this, but during the times that Unity crashes, or my PC crashes for some reason, this was a big lifesaver.
     
    Last edited: Jul 4, 2014
  22. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,655
    That's weird - I was always told that doing a 'Save Scene' already did a Save Project as well.
     
    AnomalusUndrdog likes this.
  23. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,553
    Well in my experience, and I can verify this since I do version control: in my commit screen it tells me when something has changed, stuff like gui skin files, prefab files, serialized scriptable object files... changes to them only get applied when I click save project.

    Also, try this: do changes to your prefab, change the value of some variables. Then duplicate that file. The duplicate will still have the old values, since it's based on the file, and the file hasn't gotten the changes applied to it yet, unless you force it with "save project".

    EDIT: Huh! I think you're right! At least in 4.5.0, it looks like save scene does indeed save changes to assets too. Or maybe I simply had the wrong assumption the entire time...
     
    Last edited: Jul 4, 2014
    knunery likes this.
  24. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    Allow to show hierarchy of prefab using toggle. Useful when use prefabs to split big scene apart for parallel working.

    We need inplace editing like shown on Unite 2012 and single editing where we see only prefab without surrounding scene.
    Also we need to be able to deliver some modification from instance to prefab e.g. when enter inplace editing allow to see clear prefab and prefab instance may be using toggle and allow apply some modifications from instance to prefab, so this "This would not be done if we go down the path above" is a bad thought.

    We also want to enter prefab single editing mode right from project view by Double Clicking on prefab .
     
  25. stepan-stulov

    stepan-stulov

    Joined:
    Nov 26, 2013
    Posts:
    28
    Who are you?

    Software developer (mostly Unity3D) at the moment in a German company making hybrid games.
    We use Unity3D a lot for prototyping and production on a daily basis in teams and solo.

    What kind of game are you trying to build or would like to build?

    We're building a content heavy local multiplayer competitive game.

    How do prefabs fit into that? What use-cases do you have?

    We make very solid use of prefabs. We have a very big multitude of content entities saved to custom asset files. Most of those entities have to be represented on the screen at ambiguous moments of time as a result of the gameplay / player's decisions. Thus what's seen on the screen is data driven, which means instantiating lots of stuff on the fly based on the passed data. This sounds like a perfect example of using prefabs. Often there is a need for some "macro" prefabs to contains instances of "micro" prefabs, with lots of cross-sharing too. This is where we hit the unpleasantly low ceiling.

    What about the current prefab system isn't working for you?

    Obviously, as thousands of forum fellows already mentioned, we're not happy with not being able to nest prefabs.

    My personal understanding of how nested prefabs should work has already been described here by someone, who is as me a developer with Adobe Flash background. Basically I see movie clips and movie clip instances. When somebody designs a prefab, he/she might place more instances of another prefabs inside of the parent prefab. When such prefab is instantiated, the child instances are automatically created with the individual properties specified at the parent prefab design time. Seems fairly simple and straightforward.

    There should also be two prefab editing modes (let me steal this from Adobe Flash):

    Isolated, when you edit a prefab as is, not though it's instance.
    In Instance, when you edit a prefab through it's instance by greying out the rest of the scene indicating you're about to make changes.

    The limitation of Flash is that movie clip instances can only have very few properties individually. Mostly it's just coordinates, filters, visibility and such. If you're editing the movie clip as whole through an instance, you're automatically change all the instances. There is no "Apply" button, it applies immediately. But maybe this is for the good, I imagine having individual parenting structure while still being instance of a prefab would make your brain boil.

    What I do like about Flash system the most, is that movie clips specify a type (in ActionScript 3 there is a Class class, and in C# there is a Type class) rather than a prototype object. It gives possibility to not only nesting, but inheritance. When you make a super deep tree of instances in instances in instances, specify a class name for the monster, and then make a new class by extending that class. Such inheritance however is only possible in code, not in editor. If you want to reference such class for instantiating, you simply do:

    Code (JavaScript):
    1. var shardClass:Class = assets.movieClips.shards.StoneShard;
    2. var shard:Shard = new shardClass();
    Now here is the fact that also probably creates the biggest confusion among developers both in their head and in there language. A prefab and a prefab instance both have the same type GameObject. While in flash there is a type, and there is an instance of that type. How often do we have to hear unclear things like "I have a prefab in my scene" or "I have a game object linked to a prefab" that semantically make no sense.

    What I would like to see (although not hoping too much) is incorporating the prefabs into the C# reflection system. Now, I understand that Unity has its own subsystem of instantiating a serializing things, so I wouldn't demand those types to be instantiatable (is there even such a word) through the new operator. But I want to see an instance being an instance of a type, not of another instance. Such will automatically resolve the confusion.

    Sorry for a messy opinion.
    What exactly I require is simply completely unchaining the concept of prefabs and prefabs instances from one another and allowing nesting.
     
    JesOb likes this.
  26. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,325
    You can click on the links to open the dependency.
    Ideally the links are curved to afford better visibility.
    Also color coding or icons would be good to show dependencies of type prefab and dependency inside a script, for example WeirdManager.instance.DoThing().
    This can be extended to the inspector which I personally like since it gives a synchonized view, but I didn't want to scare you off as it can seem overwhelming when not live animated.
    Note that the links need to highlight on over to provide feedback. The current editor design lacks 'over' state which is a bad thing in UX design but in the case of a widget this thing, a very bad thing.

    Soldier use goop, explosion and other things, the links point from project to hierarchy but they could be from hierarchy to hierarchy or even a curved loop if the objects references in the Soldier GO's script are contained within the solider hierarchy.
    Note the horizontal line to show that the line comes from beyond the view. I am sure you folks will find a more visually pleasing expression.
    1.png

    The links between soldier and manager are script links. they are dotted because the dependencies is hidden in the hierarchy
    2.png

    when you open the manager hierarchy, the links are now plain line and you can see the true dependencies.
    3.png
     
  27. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I would like to request the ability to undo "apply to prefab". I sometimes accidentally hit 'Apply' when I shouldn't have, and put in some values that were specific to one instance of a prefab, into every prefab. Sometimes this ruins every single setting on those. If it involved changing or removing or adding components, it's not hard to imagine a scenario where a single misplaced 'Apply to Prefab' can wreck a project to the point of having to restore from a backup.
     
    Jingle-Fett likes this.
  28. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
  29. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Version control solves that problem
     
    rakkarage likes this.
  30. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    "I can't get rid of this rat in the kitchen that keeps eating my food."

    "You can still set fire to the house, can't you?"
     
  31. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    What this implies is that you're not already using version control...

    It's not "setting fire to the house", it's "keeping your house in order". ;)
     
  32. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    Version Control does not help work fast it just help roll back mistakes.
    But with mistakes it rolls back all you changes.

    If I apply something to prefab that work 5 minutes and apply again and again and again and after that make mistake and apply something that I don't want to apply than with version control I must to start from beginning and with "undo apply" just make undo.
     
    StarManta likes this.
  33. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    It's not perfect, that much is true. And I agree, an undo on that feature would be awesome. (I never disagreed with that. I just suggested that people should use a VCS either way.)

    Having said that, you shouldn't have to undo everything since your last commit - you can just pick one file and revert that. With that in mind, if you're losing large amounts of work you might not be committing often enough... though that's of course debatable, and when you're working in a small team or as the only coder it's easy to go a long time between commits.

    (When I'm doing hobby stuff at home I typically commit once a night, at the end. At work I probably commit more like once an hour, whenever I finish some task unit. It's worth making the distinction that I generally only get to do one 'task' a night on my hobby stuff, so perhaps it works out to being about the same...)
     
  34. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I certainly understand what you mean. But, hitting "Apply Prefab" means that you are saving the changes to a file. From that perspective, it would be comparable to ask for an undo for saving the scene.
    From my point of view, it still would make sense to make it visually clearer that the button is not just a simple operation.
     
  35. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    Yes you are right but I loose last Hour of my work with prefab file.
     
  36. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    That's actually a really good point. You're spot on that it's saving something to a file... so why isn't it treated like that? There's no one-button way to save a scene - it's a two-button shortcut, or a two-click menu selection, and that's for good reason. Why is there a one-click way to save a prefab?

    Also, changing the word "Apply" to "Save" might get people in more of an "I am permanently writing something to disk" mindset. Most things that you "Apply" can pretty easily be un-applied. It's a word typically used when setting a mode or confirming a selection. It is not typically used for destructive operations. "Save", on the other hand, is a word where users innately understand that whatever was there before will be overwritten.

    I know that we consciously know that, but still... I do hear from time to time about people mentioning accidentally "applying" prefabs, and it's a common warning to newbies to be careful about when they "apply". But when is the last time you ever heard either of those about saving a scene?
     
  37. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    If I'm in Photoshop, and accidentally hit command-S when I didn't mean to save something, I can still command-Z through the history of the file and save the old one. There is no comparable operation with prefabs.
     
  38. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    We are talking about "Apply" prefab, meaning you modify a prefab instance in the scene and then apply the changes to the prefab. There you have the possibility to undo the changes in the scene and apply again, just as in Photoshop.
     
  39. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Perhaps a more clear understanding of what I'm doing with the prefab would help explain why this is not the case. I have a prefab of a game element called a spinner. The spinner contains references to several other nearby spinners, the velocity at which the spinner must launch the player to get to those spinners, the ID of the spinner, whether the spinner is a checkpoint or not, etc etc etc. Most of these spinners have vastly different values for these. Occasionally, the default values for the spinner work fine, and the spinner has the defaults.

    So now I'm working on a spinner where the launch velocity to nearby spinner #1 is 25, while the default is 15. Probably 20 or 30 spinners in the game have the default value of 15. I do some stuff, then accidentally hit apply on the 25-velocity spinner. Now all those spinners have a launch velocity of 25, and the player is flying past spinners or hitting ceilings on those. (Keep in mind that this system is much more complex than is actually laid out here, and I have 10-30 numbers like this, each of which could break some of the spinners in the game.)

    I don't think this use case for prefabs - with a complex mix of default and non-default values across many instances - is uncommon. And hitting 'apply' with the wrong one selected can easily break your game. And no, I don't consider SCM the "right" answer here. Reverting to the last commit is the last resort when something goes wrong that you really can't fix.
     
  40. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    I tried that, if I hit apply only the original prefab gets the new value. All instances with custom values Keep their values.
     
  41. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    The ones that have custom values are fine, but many of them have and rely on the default value.
     
  42. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You just need to tell me that it is no possible to undo changes after you hit "Apply" :) . I thought this is possible and I was wrong.
    But it still doesn't change the way I think of prefabs. They are separate files and as such the "Apply" should be more special to highlight it. In Unity there is no undo for file operations.
     
  43. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Ah, sorry. But those with a default value will change back to your new default value.
    So if you accidently click apply, you can change it back, hit apply again and everything is back to normal.
     
  44. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,655
    I wouldn't say it's comparable to a save - for starters I'm not sure that Apply actually does save to disk, but more importantly, a Save operation should only ever sync what you're seeing in the editor to disk in a way that does not change what you're seeing in the editor, and Apply doesn't meet that requirement.
     
  45. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Save may not be the best comparison. Maybe baking a texture atlas in a 3D application is a better comparison. It will replace the old baked texture, may change the uv layout and influences all the models and materials that are using it.
     
  46. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,655
    OK, but I'd say 'undo this bake and go back to the old atlas/UVs' is a reasonable request :)
     
  47. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Saving the scene automatically saves the project at the same time already - it's always been that way.
     
  48. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,553
    I realize my confusion is when I edit some asset, like a GUISkin, and then I close Unity, then the prompt saying "save the scene?" I choose don't save because I wasn't intending to edit the scene during that time anyway, not realizing I should have done that to save my changes to the GUISkin as well.
     
  49. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Ah, gotcha. Unity 5 is supposed to fix that (as mentioned in the Unite Keynote).
     
  50. BrainMelter

    BrainMelter

    Joined:
    Nov 20, 2012
    Posts:
    572
    Yeah this is really annoying, especially if Unity crashes and you haven't saved your scene.
     
Thread Status:
Not open for further replies.