Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Assets [WIP] Greenfab - Better Prefabs

Discussion in 'Works In Progress' started by MichaelKatic, Feb 15, 2018.

  1. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Intro
    Howdy y'all!

    In the game my team is working on we have lot's of prefabs, like most Unity projects. For our environment we have simple prefabs like flower, tree, etc. Then we have groupings of these that the artists set up to look pretty. Problem is when we turn these groupings into prefabs we can no longer update all the child prefabs that pointed at the simple stuff. For example, if we change a flower, we have to update every prefab group with the flower in it! This can take hours.

    Similar Assets
    It's crazy that Unity doesn't support having these "nested prefabs," because so many people want them. Granted they are working on them but they've been doing so for a while.

    Looking at the asset store there are quite a few solutions but anything decent is pricey. Here's a couple take aways from what is out there.

    Nested Prefabs - This is probably the most polished and looks to have some great support. It's $45 which is a bit but plenty justifiable. One of the weirdest quirks is the locking attributes system. Unity stops prefabs from overwriting an instances edited attributes. In Nested Prefabs they have an interface for manually locking these fields. It's less automatic but allows to force overwriting without reverting. It really is just the same as Unity's Revert>Apply. Everything else about this looks very clean though. They do depend on the UnityEditor so this cannot be used in a build. Also, they override the Unity prefabs functionality which some people may not like.

    Prefab Evolution - This is a bit of a reinvention in the prefab UI but a decent tool from what I've seen. The developer isn't the most consistent but this assets has been around since 2014. This also has a very nice custom UI and doesn't override normal prefab functionality. Biggest downside is the low quality introduction videos. This isn't the easiest solution to jump into.

    This Asset
    Greenfab - This tool I believe comes with some unique features. I think it's the only one can be used without UnityEditor and also the only one that let's you retarget your prefabs. Here is a full list of features.
    • Prefab Nesting - Revert a single prefab and all child prefabs in one click.
    • Prefab Re-Targeting - Change the prefab reference to any GameObject.
    • Multi Object Editing - Select and revert any number of prefabs at once.
    • UnityEditor Independent Implementation - Uses .NET Reflection so that prefab reverting can be called from any application build.
    • Verbose Output - Output available for all attempts prefab reverting.
    • Custom Editor - Shows green text for Greenfab prefabs in Unity hierarchy.
    • Works with Unity Prefabs - Doesn't impede the usage of regular unity prefab functionality.
    Here is a few samples of it in action.

    Prefab Nesting and Multi-Object Editing


    Prefab Retargeting


    Verbose Output for Multi-Object Editing


    Video Walkthrough Demonstration
     
    Last edited: Apr 2, 2018
  2. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Small Update
    I added a few more changes today.
    • Auto Top Anchor - Prefab Link component is now automatically pushed to the top of the components list, right under Transform.
    • More Formatting - Just some changes to the layout to make this a little less obtrusive.
    • Project View Reverting - Added some conditions where it let's you revert and apply in the project view menu. If the target is equal to the object being inspected then the "Revert" and "Apply" buttons are grayed out.
    Project View Reverting Disabled


    Project View Reverting Enabled
     
  3. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Update: Icons!

    I added some cute little green icons. I still have not figured out how to override the prefab icon in the project window. The guy who made this said he used a hack to draw over the folder icons. Sigh. That sounds fun!

     
  4. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Update: Undo working!
    I have finally been able to get undo working for all functions. This was pretty important since this could destroy tons of prefabs at once if you're not careful. Yay!

    The only thing not working is the Apply. I am temporarily using the UnityEditor apply and apparently it doesn't play well with undo. I will soon replace this with my reflection revert flipped around, then undo should work fine.
     
    Last edited: Feb 17, 2018
  5. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Update: Souce and Logo
    Back again. Even though this thread is still locked and awaiting moderation. Doh!

    Source is now available on GitHub. It's missing my ExtensionsMethods right now. I'll add a repo for that later.

    Here is the logo I threw together.
     
    Last edited: Apr 2, 2018
  6. scritchy

    scritchy

    Joined:
    Dec 30, 2010
    Posts:
    90
    Hi there. This is interesting. I want to experiment with it, but the github doesn't have a mention of any licensing terms, so I don't feel I can check it out. Would you be willing to choose and apply one of the "open source" licenses for this? Or is your intent to commercialize/sell it in asset store when it's ready? Either way, what's your expectations on various developer's ability to use your plugin?

    Thanks!
     
  7. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Hi Scritchy! I've just pushed an update with the license included. This licenses is based on the license distributed with all assets on the Unity Asset store. It basically protects it from being redistributed as an asset but allows usage in games and applications. Here is a link the Unity AS License which is a little easier to read and navigate.

    Update!
    I've included the dependency Extension Methods source on our GitHub so everyone should be able to compile Greenfab now. I'll try to make a neat little package to distribute soon.
     
    theANMATOR2b likes this.
  8. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Update: Unity Package Download Available

    You can now download the Greenfab Unity package here! It's free for now, while it's in beta.
     
  9. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Update: Better Prefab Target Handling

    The power of the prefab re-targeting comes with great responsibility. This week I...
    1. Cleaned up the way target references are handled when adding the PrefabLink component
    2. Also, better linking when when turning a GameObject with a PrefabLink into a regular prefab.
    3. Added a button for creating a new prefab if one does not exist. This pops up the file save prompt and handles the linking after it's saved.
    Here is an overview that shows each of these 3 changes.



    One of the changes required some code that is not the most scaleable and currently wont work on project with thousands of prefabs. I needed to update the instances of a unity prefab after it's created and only have a reference to the prefab. Unity doesn't manage prefab instances so in the PrefabUtility there is no method that returns instances of that prefab. Later, we're probably best off to create our own structure to track these references so we can be super fast. Here is a link to the slow code :(

    The new updates can be downloaded here.
     
    BlackDragonBE likes this.
  10. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Update: Multi-Prefab Creation

    You can now create multiple prefab at once using the create prefab button. All you do is:
    1. Select multiple game object in your scene
    2. Click "Create Prefabs"
    3. Select to "Skip Prompts" (save all with default name) or "Show Each Prompt" select location for each prefab.
    Here is a preview:
     
    BlackDragonBE likes this.
  11. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Update: Multi Target Editing and Targeting GameObjects

    I just added multi target editing so you can set the Prefab Target on multiple PrefabLink components at once.



    Also, targeting GameObjects in a scene has always been a thing but I've not showed it off. One of the advantages this tool has is that you do not have to revert or apply from a prefab in your assets folder, you can target any GameObject anywhere. Here is an example:

     
    BlackDragonBE likes this.
  12. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Update: Advanced Options, Deep Value Checking Equality, and More!

    I've added an "Advanced" dropdown with some extra settings that have come in handy for development. You can now choose if you want to update names of prefabs being changed or not with the "Change Names" toggle.

    Reverting GameObject Names


    Also, while I like my custom Apply / Revert, there are still times when the tried and true UnityEngine implementations may be needed. For this I added a couple of toggles that switch the background logic.

    Using Unity's Apply/Revert


    The coolest addition this week is the new equality check we added. It does a super deep delve into each GameObject and it's Components to compare all the accessible fields and properties. Of course it only does this if there isn't an overloaded Equals implemented already. You can see the PrefabLink component for example. Also, things are getting pretty complex so we've included some better debug output and a toggle for Verbose.

    Game Object Deep Value Based Equality Checking and Verbose Output


    Lastly, this deep checking can be expensive so I've included the option to turn it off and to manually check for object changes.

    Manually Check if Prefab is Dirty to Save on Performance


    One thing I've still not done with all these new features is add persistent saving. It can be really annoying changing the settings all the time but I will do my best to get that in soon.

    The latest Unity Package can be downloaded here. As always if you have input feel free to speak up. Would love for some more ideas.

    Thanks everyone!
     
    BlackDragonBE likes this.
  13. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Update: Bug Fixes Galore!

    I released a buggy piece of S*** last week. This week I've fixed all those bugs and more! No fancy gifs to show but everything should be a lot smoother now and behave more intuitively now. Here are some of the details. Also you can always view the source's latest commit for changes.
    • Fixed bugs with reverting all and applying all.
    • Untied Revert and Apply functions from "this" and "target" so they can destroy the objects they are working on without creating a null ref exception.
    • Now we have an Apply and Revert that use the "this" gameObject and "target" and they behave how unity Apply and Rever behave. Underneath we have a generic Copy function that that takes a from and to param.
    • Added editor colors for when a PrefabLink is missing it's target link.
    • Fixed bugs with the way targets are managed when dragging prefabLinks into Heirarchy and Project windows.
    • Lots of code cleanup.
    Download Package Here
     
    Ethan_VisualVocal and MostHated like this.
  14. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    555
    WoW, this is great! Thank you!
     
    MichaelKatic likes this.
  15. tbriley

    tbriley

    Joined:
    Sep 10, 2013
    Posts:
    35
    looks great, will follow here for updates :)
     
    MichaelKatic likes this.
  16. MichaelKatic

    MichaelKatic

    Joined:
    Mar 22, 2013
    Posts:
    14
    Hi everyone!

    I've been working on a really big change that will enable better control over how objects are managed with Greenfab. One of the biggest issues right not is loss of inspector linking. Before reverting (or applying) worked like this:
    • Delete the root GameObject's children
    • Copy GameObject children from target
    • Delete the root GameObject's components
    • Copy components from target
    This means that reference to any child or component on a PreafabLink would be lost. To fix this we need a non destructive revert/apply that only copies the values of each component. It also has to detect remove or added components or GameObjects from the hierarchy.

    And that is what I've been working on for the last few weeks. This also proved complicated enough to justify creating better debug visualizations so that's in development too. Here's a preview of what's new:

    • Non Destructive Copying - Reverts/Apply changes on a per GameObject per Component level, allowing you to keep old references intact.
    • Dirty Report - A report that gives you a complete 1 to 1 match up of how PrefabLink determines equality and decides what to destroy and what to copy. Right now it's just a flat list but I plan to add a hierarchy view option.
    And here is how it looks...

    Adding a New Component


    Changing Component Fields


    This still has some bugs to work out and I don't have a build ready. I just wanted to stop by to let everyone know what's going on since it's been a few weeks.

    Cheers!
     
    BlackDragonBE likes this.