Search Unity

Prefab Evolution Plugin(nested prefabs)

Discussion in 'Works In Progress - Archive' started by PrefabEvolution, Mar 27, 2014.

  1. halfbot

    halfbot

    Joined:
    Sep 22, 2013
    Posts:
    19
    OOps. You are correct. It worked. I had to reimport the asset after the move but it works fine. Thanks.
    Also, thanks for the response on the source. You reasons makes sense. You assurance for full support and a future source release is enough for me.

    @Remiel, I may be wrong but if you remove the asset due to a future bug or show stopper you would simply need to remove the accompanying script from the prefab. The prefab itself would still work. @PrefabEvolution please correct me if I am wrong.
     
  2. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Absolutely right. This plugin do its work only when you click apply.
     
    Last edited: May 24, 2014
  3. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225

    For the better meaning i would like to explain you some internal things thats happen inside.
    The magic happens only when you press apply button or import model that was nested inside another prefab.
    All this system is not complicated. Its have 4 most important classes:

    Cache - ScriptableObject thats work behind the scene and collect prefabs dependencies. So its just build dictionary where key is "Prefab", and value is "Prefabs that contains prefab in key". So this dictionary updates after you import model or apply changes to prefab.

    EvolvePrefab - MonoBehavior that contains all information about current prefab instance: PrefabRef, ParentPrefabRef(if inherited from another prefab), Linkage and Modifications. Its only container to save some metadata with this Prefab Instance.

    Linkage - Some thing like a Dictionary<ChildObjectGUID, CurrentChildObjectRef>. Every time when you click apply its collect all child objects(GameObjects, Components) and add it to dictionary. For every new object that was not found in dictionary its create a new GUID. GUID is required to determine prefab object for every prefab instance object.

    Modifications - Contains changes that was mede over current prefab instance, or child prefab. Its contains information about changed properties, new objects, removed objects and about GameObjects that changed their parent. This information is necessary to apply all this changes after prefab or parent prefab is changed.

    So what happen when you click Apply:
    Code (csharp):
    1.  
    2. //Pseudocode
    3. Apply()
    4. {
    5.     this.BuildModifications();
    6.     this.BuildLinks();
    7.     foreach(var prefab in Cache.FindPrefabsWithNestedInstancesAndChildrenOf(this))
    8.     {
    9.         foreach(var nestedInstance in prefab.GetNestedInstancesAndChildrenOf(this))
    10.         {
    11.             nestedInstance.ReplaceWith(this, nestedInstance.Modifications);
    12.         }
    13.           prefab.Apply();
    14.       }
    15. }    
    16.  






     
    Last edited: May 24, 2014
  4. EricM

    EricM

    Joined:
    Aug 17, 2013
    Posts:
    10
    Nice plugin. It does what it says it will do and is providing a few new options for me when loading scenes from prefabs. Thanks! How do you remove the work your plugin does to an object/prefab that was already converted to your system?

    I had a few objects I enabled through your plugin and realized I would never need to nest them or their use in nested prefab chains would be too prone to error, but I couldn't find a way to cleaning revert the prefab to it's original "native prefab" state or even just a clean non-prefab state. Any advice?
     
  5. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    You can just remove EvolvePrefab Script from root of your prefab to prevent nesting them inside another prefab. But if you would like disable link only for current prefab instance you can Disable it in menu and it will never changed when the prefab changed.
     
    Last edited: May 29, 2014
  6. EricM

    EricM

    Joined:
    Aug 17, 2013
    Posts:
    10
    Thanks. Good to know it's safe to just remove the script. However, I'm not seeing the disable option in Prefab Evolution's menu though. You're referring to the menu button right above transforms, correct?
     
  7. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Disable button exits only on prefabs that nested inside another(when its have a yellow cube icon in hierarchy). And absolutely safe to remove EvolvePrefab scrips. Its just because this plugin do his work only when you click apply button, not in runtime, even not in edit mode. To understand how its really work you can imagine if you have a guy that ever when you click apply button on prefab manually open all nested prefab instances and child of current prefab, manually replace it with your new prefab, apply all extra changes that you previously applied to current nested instance(change hierarch, remove/add GameObjects/Components, change properties), and restore all external reference to the inner objects. Its just do your routine hard work. But this guy never made ​​a mistake that human can do just by their carelessness...
     
    Last edited: May 30, 2014
  8. vidjo

    vidjo

    Joined:
    Sep 8, 2013
    Posts:
    97
    Hello, one feature I would really like is the ability to insert a parent into a PrefabEvolution inheritance hierarchy.

    What I mean is.. If I have

    -BaseObject
    --Object1_a
    --Object2_a
    --Object3_a
    --Object1_b
    --Object2_b
    --Object3_b

    I want to be able to both insert a new parent before BaseObject, and also have the option to replace BaseObject with new object, but make BaseObject the parent of the new object. It would probably make sense to be able to select prefabs.. say I select Object1_a, Object2_a and Object3_a, and then have a button "insert parent" that will insert a parent between those objects and their parent. Then the prefab hierarchy would look something like this:

    -BaseObject
    --Object1_b
    --Object2_b
    --Object3_b
    --NewInsertedParentPrefab
    ---Object1_a
    ---Object2_a
    ---Object3_a

    So now I can make changes on the NewInsertedParentPrefab and they will apply to Object1_a, Object2_a and Object3_a.
     
  9. halfbot

    halfbot

    Joined:
    Sep 22, 2013
    Posts:
    19
    Hey PrefabEvolution can you help me out. I am getting this errors since upgrading to 4.5. It happens when i hit apply:

    Mismatched types in GetValue - return value is junk
    UnityEditor.SerializedProperty:get_rectValue()
    PrefabEvolution.PEUtils:getPropertyValue(SerializedProperty)
    PrefabEvolution.PEModificationsExt:CalculateModifications(PEModifications, PrefabScript, PrefabScript)
    PrefabEvolution.PrefabScriptExt:BuildModifications(PrefabScript)
    PrefabEvolution.PrefabScriptExt:ApplyChanges(PrefabScript, Boolean)
    PrefabEvolution.GameObjectInspectorOverride:Apply(GameObject)
    PrefabEvolution.GameObjectInspectorOverride:Apply(GameObject[])
    PrefabEvolution.GameObjectInspectorOverride:Apply()
    PrefabEvolution.GameObjectInspectorOverride:OnHeaderGUI()
    UnityEditor.DockArea:OnGUI()
     
  10. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Submit new build to support 4.5, and you can also send me message on PrefabEvolution@gmail.com and i send you build with fixes.
     
  11. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Honestly this feature is already implemented and i test it now. In near future its will be published. You can also insert parent for any child prefab or for every children.

    something like:
    base=>Child1
    ------\=>Child2

    to

    base=>InsertedChild=>Child1
    ------\=>Child2

    or

    base=>InsertedChild=>Child1
    -----------------------------\=>Child2
     
    Last edited: May 30, 2014
  12. EricM

    EricM

    Joined:
    Aug 17, 2013
    Posts:
    10
    Thanks, this helps me wrap m head around the best way to use this. Cheers!
     
  13. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Version for Unity 4.5 now available on Asset Store!
     
  14. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
  15. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    On weekends working on "Properties Shortcuts". And submit this new feature on Asset Store soon it will be available.

    Now its possible to create a shortcuts on any property inside prefab. You can group, sort any properties by drag&drop.
    Its very convenient when you have very large prefab with many properties and game objects and now you don't need to dig into them, just create a shortcut. Its a first step to make prefabs encapsulation. Also inherited prefabs can extend property list or hide parent properties. I'd like to see your review for this feature:)
    Screen Shot 2014-06-03 at 14.12.29.png

    Screen Shot 2014-06-03 at 14.13.18.png

    Screen Shot 2014-06-03 at 14.15.01.png

    Who would like to try it right now Download Trial
    Or send me you Invoice to prefabevolution@gmail.com to get recent Full version
     
    Last edited: Jun 3, 2014
  16. EndOfDayz

    EndOfDayz

    Joined:
    Jun 4, 2014
    Posts:
    2
    does this plugin also work on mobile plattforms?
     
  17. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    This plugin do nothing at runtime. Its only editor extension and its works on any platform.
    Moreover now this plugin spliced into 2 libraries PrefabEvolution.dll & Editor/PrefabEvolution_Editor.dll .
    Editor/PrefabEvolution_Editor.dll - this library hold all main methods to handle needed/inherited prefabs GUI and so on.
    PrefabEvolution.dll - Contains only script and internal data declaration.

    In runtime or after deploy only data still appear in build. and nothing will be executed. so you ever will see same result in editor or in player. Just because all magic occurs only in edit time.
     
    Last edited: Jun 4, 2014
  18. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    New version is available on Asset Store!
     
  19. vidjo

    vidjo

    Joined:
    Sep 8, 2013
    Posts:
    97
    I get this warning (floods console, slows unity) in Unity 4.5

    "Unable to find style '' in skin 'DarkSkin' mouseMove"


    EDIT: Nevermind, I wasnt on the latest version :)
     
  20. pakmafia

    pakmafia

    Joined:
    Feb 24, 2011
    Posts:
    43
    After imorting the free version into my project i get errors.
    Internal compiler error. See the console log for more information. output was:
    Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
    at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
    at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
    at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0
    at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0
    at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0
    at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0
    at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0
    at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
     
  21. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
  22. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Today Prefab Evolution plugin is submitted for Asset Store Review. Now its come with full source code included!
    While review in progress you can get the source right now. Just mail me PrefabEvolution@gmail.com.
     
  23. vidjo

    vidjo

    Joined:
    Sep 8, 2013
    Posts:
    97
    Awesome!! Thank you for keeping your word and providing source code!!
     
  24. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Its good to be honest. And also source code allow you to extend and make this tool more useful for you. Any way i'd like to make your workflow more convenient, simpler, and save your time.:)
    I also include some code to convert current prefabs, so if you already use this plugin in your project you just import a new version with source code, remove dlls and click one button. This code just replace all current references to Script that imported from dlls to script with sources and ask you to reimport models.
     
  25. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Now Prefab Evolution Plugin with full source code is available on Asset Store!
     
  26. vidjo

    vidjo

    Joined:
    Sep 8, 2013
    Posts:
    97
    So I get this error sometimes when I apply a prefab:

    Though I never did anything strange like remove the EvolvePrefab component. Is this maybe a bug?

    I'm on Unity 4.5.1.
     
  27. vidjo

    vidjo

    Joined:
    Sep 8, 2013
    Posts:
    97
    Ok, I am able to reproduce it like this:

    Import Prefab Evolution and NGUI into your project. (I imagine you dont need NGUI to reproduce it, but this has worked for me)

    Create an empty scene.

    Turn on "Make prefabs nested on create".

    Drag some NGUI prefabs such as "Control - Colored Checkbox"

    Unity usually crashes after this. If it doesnt try dragging a couple different NGUI Control prefabs in.
     
  28. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Can you send me your editor log after crash?
     
  29. vidjo

    vidjo

    Joined:
    Sep 8, 2013
    Posts:
    97
    Hello, I would like to know how I can insert a parent into a prefab inheritance tree.
     
  30. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    You can add #define INJECTION and you will see Insert Parent item in Prefab menu. While this feature in beta test, but now you can try to test it by yourself
     
  31. vidjo

    vidjo

    Joined:
    Sep 8, 2013
    Posts:
    97
    Thank you.
     
  32. vidjo

    vidjo

    Joined:
    Sep 8, 2013
    Posts:
    97
    Ok, now if I create a child prefab, Unity crashes. Do you have any idea why this might be?

    Does PrefabEvolution store data about my project? Perhaps its corrupted and I need to start fresh?
     
  33. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Do you reimport models after migration from dlls to sources version? You should do that because data about prefab that created when importing model doesn't contains in asset folder, but inside Library folder and serialized always in binary. So now you can reimport models or all project. Im sure that reimport will solve your problem.
    So probably Unity crash when its trying to load model that contains Component with missing script.
     
  34. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
  35. wampastompa

    wampastompa

    Joined:
    Apr 19, 2014
    Posts:
    6
    Any fix on this? I'm experiencing a crash too, but only when I create children of prefabs that are NGUI objects. I'm using the latest version of Unity, NGUI, and Prefab Evolution, and it crashes consistently when I make a child of an NGUI object.

    I tried Reimporting all assets, but this crash occurs even when I create a new project and try to create a child.
     
  36. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Can you provide Editor.log after crash. I don't have any errors while working with NGUI.
     
  37. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Your trial only works in 4.5 above? Getting errors with 4.3
     
  38. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Yes, trial is only for Unity 4.5.x.
     
  39. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Found issue when Unity crash when working with NGUI and Prefab Evolution. This happens when you re trying to do EditorUtility.SetDirty() inside OnEnable().

    Today i will send package with this bugfix to Asset Store. As for now you can fix it by yourself

    Just:
    Code (csharp):
    1.  
    2. class PEExposedPropertiesEditor
    3. {
    4.        void Build()
    5.        {
    6.                ...
    7.                //targets.Foreach(EditorUtility.SetDirty);
    8.                EditorApplication.delayCall += () => targets.Foreach(EditorUtility.SetDirty);
    9.        }
    10. }
    11.  
     
  40. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Cool asset.

    Can't believe that someone finally cracked the Nested Prefab limitation.
    Question: Is it possible to make Assetbundles with these nested prefabs?
    Are there any known limitations with Asset Bundles?

    Cheers.
     
  41. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Because this plugin don't do anything in runtime(Editor only), you can use it with Asset Bundles.
     
  42. cr4y

    cr4y

    Joined:
    Jul 12, 2012
    Posts:
    44
    Hi,
    I recently bought your product and had strange situation: I'm using version control (svn). I've added nested prefab on one machine, and it's not visible as nested on another. What is more, after bringing prefab on scene, it doesn't have "Evolve Prefab" script attached. Do you have idea what can be source of problem? May it have something in common with fact that I'm using Unity pro on only one of these machines?
    Thanks in advance for any suggestions.
     
  43. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    This plugin work on Unity free. so may be you forgot to add plugin files under version control? Check that on the second machine plugin files exists.
     
  44. gstock

    gstock

    Joined:
    Feb 19, 2014
    Posts:
    10
    I'm having this error every time I import a new FBX into my project and EvolvePrefab is added to my object, which makes PrefabEvolution not working when I replace the FBX:

    MissingReferenceException: The object of type 'EvolvePrefab' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    PrefabEvolution.PEUtils.Foreach[PEPrefabScript] (IEnumerable`1 targets, System.Action`1 action) (at Assets/PrefabEvolution/Sources/Editor/PEUtils.cs:76)
    PrefabEvolution.PEExposedPropertiesEditor+<Build>c__AnonStorey15.<>m__27 () (at Assets/PrefabEvolution/Sources/Editor/PropertyExposure/PEExposedPropertiesEditor.cs:97)
    UnityEditor.EditorApplication.Internal_CallDelayFunctions ()

    If I add a Try/Catch on line 76 of PEUtils.cs, everything works fine and replacing FBX works great, but I guess this is not the right fix.

    Any Ideas?

    Thanks!!
     
  45. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Hi i have found this bug few days ago. And fixed version is now on asset store review. If you would like to get recent build you can send me your invoice id on prefabevolution@gmail.com and i send you recent build of the plugin.
     
  46. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Short video to show how Prefab Evolution plugin can be useful when you building UI. Don't repeat! Nest! Inherit!
     
  47. gstock

    gstock

    Joined:
    Feb 19, 2014
    Posts:
    10
    Hi!

    I'm trying to integrate PrefabEvolution into my AssetPostprocessor pipeline. This means creating new prefabs making them inherit from a base prefab or updating existing prefabs and adding new components. I'm experiencing some issues, and I want to be sure that my flow is correct.

    I based my code in the code of PEUtil.CreateChild() method:

    When creating a new prefab on my OnPostprocessAllAssets method I'm doing:

    Code (CSharp):
    1. basePrefab = (GameObject)AssetDatabase.LoadAssetAtPath([BASE_PREFAB_PATH], typeof(GameObject));  // This is the BASE Prefab I want to inherit from
    2. GameObject baseGo = GameObject.Instantiate(basePrefab) as GameObject;
    3.  
    4. // Add Components and Childs to baseGO
    5.  
    6. // Create new "Child Prefab" based on "baseGo"
    7.  
    8. GameObject childPrefab = PrefabUtility.CreatePrefab(prefabPath, baseGo, ReplacePrefabOptions.Default);
    9. PEPrefabScript childPEPrefabScript = childPrefab.GetComponent<PEPrefabScript>();
    10.  
    11. childPEPrefabScript.Prefab = childPrefab;
    12. childPEPrefabScript.ParentPrefab = basePEPrefabScript.Prefab;
    13. childPEPrefabScript.ParentPrefabGUID = basePEPrefabScript.PrefabGUID;
    14. childPEPrefabScript.BuildModifications();
    15. //AssetDatabase.ImportAsset(path); <----- Not doing this because I'm actually on the import process
    16. PECache.Instance.CheckPrefab(prefabPath);
    17.  
    18. GameObject.DestroyImmediate(baseGo);
    If the "Child Prefab" already exists I open it and make the modifications over it:

    Code (CSharp):
    1. basePrefab = (GameObject)AssetDatabase.LoadAssetAtPath([PATH_TO_CHILD_PREFAB], typeof(GameObject)); // This prefab already inherits from "BASE Prefab"
    2. GameObject baseGo = GameObject.Instantiate(basePrefab) as GameObject;
    3.  
    4. // Add Components and Childs to baseGO
    5.  
    6. // Save prefab using Prefab Evolution Apply Method
    7.  
    8. var root = PrefabUtility.FindPrefabRoot(baseGO);
    9. var pi = root.GetComponent<PEPrefabScript>();
    10. PEUtils.DoApply(pi);
    I'm having some problems when updating existing child prefabs, for example all the child instances on the scene get reseted to the "child prefab" values (Position, name, etc).

    Is my flow correct? I've dig into PE source code, but could't get the right flow to update prefabs.

    Any help is appreciated!

    Thanks
     
  48. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Behavior of the instance on scene are not affected by this plugin.
    1. you should check that properties on scene prefab instances are overridden(Unity should draw theirs name bold). If not you should manually invoke UnityEditor.EditorUtility.SetDirty(obj); on them. Its happens when you changing object properties directly from code and don't notify UnityEditor about it. So you should every time when you change any serialized field from code, you should call SetDirty on this object.
    2. Not good idea to do any changes on assets import process. Its more safe to call your functions like that : EditorApplication.delayCall+=()=>PEUtils.DoApply(prefabScript);
     
  49. Bob-M

    Bob-M

    Joined:
    Aug 31, 2013
    Posts:
    1
    Hello,
    Empty GameObject's Transform's Scale Problem.

    1) Make EmptyGameObject, rename to <ObjectA>. and make it nested prefab.
    2) Create another EmptyGameObject, Change name to <Container>
    3) Duplicate ObjectA-2 and move it under the <Container>
    4) Make <Container> to prefab.

    5) Change <ObjectA>'s Scale value and Apply.
    6) Container's ObjectA-2 is not affected.

    Is it by design? I think it have to be fixed.
    Thanks.
     
  50. gstock

    gstock

    Joined:
    Feb 19, 2014
    Posts:
    10
    Finally fixed my problem!

    I was using:
    1. GameObject baseGo = GameObject.Instantiate(basePrefab) as GameObject;
    To instantiate prefabs instead of using

    Code (CSharp):
    1. GameObject baseGo = PrefabUtility.InstantiatePrefab(basePrefab) as GameObject;
    Changing the call to PrefabUtility.InstantiatePrefab fixed all my issues.

    Thanks!