Search Unity

Presets Feature

Discussion in 'Editor Workflows' started by markvi, Aug 29, 2017.

  1. hadisajjadi

    hadisajjadi

    Joined:
    Feb 7, 2018
    Posts:
    5
    Very Cool This Is a Great Feature, Thanks.
     
  2. Candy_Smith

    Candy_Smith

    Joined:
    May 8, 2014
    Posts:
    102
    Please make presets available from the runtime.
    It could be very useful.
    It will allow us to save different conditions of gameobject (transform component i e) and switch depending on a situation.

    Thank you
     
  3. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    Hi Candy_Smith!
    Unfortunately, the Preset feature relies on a lot of editors only serialization features that are slow and heavy processes based on variables names and types, which we don't want to include at runtime to avoid memory and performances issues.
     
    codestage and Candy_Smith like this.
  4. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    so we have no set preset in runtime ?
     
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    That's right. Currently it is an editor-only feature.
     
  6. douglassophies

    douglassophies

    Joined:
    Jun 17, 2012
    Posts:
    141
    Is there a way to exclude some fields from presets? For example i want to use the same mesh render settings for many objects but i want the materials to stay the same. Can i tell the materials not to change on application, or better yet, not save info like the material to the preset?
     
  7. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    Hi Douglas!
    Not at the moment, but this is worked on for a future Unity version.
    Until that, coming in 2018.3 the ApplyTo method will have a new optional string[] argument to specify which property you want to apply. Others properties will then be ignored in the Preset.
    We are aware that it is not the best solution, but some more work is needed to support Partial Preset from Inspector and we thought that this temporary solution may save part of the problems.
     
    codestage likes this.
  8. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    Couldn't you manually edit the preset file? As in you could open the .presets file in a text editor, find the material entry, and delete it.

    It did a quick experiment, and it seems like that works as expected, so it might be an OK stopgap.

    The editor will be a lot harder to solve, so good luck with that.
     
  9. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    It should not work. The deleted entry will be added back using Unity's default value whenever the Preset is loaded in memory.
    This is to make sure a Preset always have information about every field of an Object, in case someone added a new serialized member after the first Preset creation.
    However, the changes are not written back to the .preset file until a manual change is done to it - because it is automatic and deterministic and we don't want to bother ever user with that kind of change if it's not necessary.
     
  10. douglassophies

    douglassophies

    Joined:
    Jun 17, 2012
    Posts:
    141
    The temporary work around sounds like it will help a lot, thanks!
     
  11. playsportmatt

    playsportmatt

    Joined:
    Sep 1, 2016
    Posts:
    5
    I'm using 2018.2.0f2 should this work with UI elements? I've set a default Image preset (turns it red & unticks raycast target) but it isn't be applied to any of the images I create via the context menu. I can apply it manually.

    preset1.PNG

    preset2.PNG
     
  12. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    It looks like the default is not applied to any components created under the GameObject/UI menu. We are looking into the issue and will figure out a fix for it. Thanks!
     
    TimHeijden2 likes this.
  13. TimHeijden2

    TimHeijden2

    Joined:
    Aug 11, 2016
    Posts:
    86
    Making this work for UI context menu would be awesome, do you think this will be in by 2018.4?
     
  14. megaestudio

    megaestudio

    Joined:
    Aug 7, 2017
    Posts:
    1
    Hello people,

    1. How to access to change presets by script ?.
    2. Is it also allowed to do it with InputManager?
    Thanks
     

    Attached Files:

  15. TommySKD

    TommySKD

    Joined:
    Jul 23, 2014
    Posts:
    25
    They're great and work well for a lot of things but why aren't ParticleSystems renderer components supported? It is pretty annoying since there are actually a lot of important stuff in there for almost any particle and you have to redo it everytime..
    It is even more annoying because presets could be very useful for particlesystems, but that limitation is ughh I'd rather stick to template prefabs particlesystems because of it.
    Im guessing under the hood the particlesystem renderer component is *actually* a different hidden component so preset don't work or whatever but I dunno maybe a way to include it in the preset then since every particlesystem has one anyways?
     
  16. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    @bastien_humeau, could you consider adding a temporary copy-paste feature for this? Essentially similar to "copy component/paste component values" that's available from the cog on MonoBehaviours.

    The use case is this: I have an imported texture, and I want a different texture to have the same import settings. I don't want to create a permanent preset, I just want to copy the settings this one time. Right now I either have to create a preset, apply it, and then delete it again, or just copy over the settings manually.

    I'm not quite sure how this would look in the UI, but the functionality would come in very handy pretty often when working with assets.
     
  17. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Hi @bastien_humeau

    Being able to save my Inspector settings with preset select has saved my life countless times. So thank you for it.

    But is there a way to make the Preset Select more responsive?

    I have to click on it 5-10 times before it opens up.. But then Unity remembers all the clicks and it goes crazy opening\closing the Presets window. :(

    Thanks!
     
  18. JPFerreiraVB

    JPFerreiraVB

    Joined:
    Sep 18, 2017
    Posts:
    39
    I'm having a issue. Even if i manually try to override the project settings via the .preset asset i get a unity Crash.

    Here is how you can reproduce the error.

    Open one project -> Go to ProjectSettings Window -> Save any setting as .preset
    Open new project -> Drag and drop the .preset do the Asset folder -> Go to ProjectSettings Window -> Click the slider icon -> Select the .preset -> Bam Unity Crash

    Any input on this?

    EDIT
    -----------------------------------------------------
    It only happens for the PlayerSettings.preset
    The Quality / Tag settings.preset works fine.
     
    Last edited: Jan 31, 2019
  19. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    I'll add it to our list of features to look at, not sure if we will do it, but I like the idea :)

    Can you open a bug for it using the bug report in Unity? Being slow is a problem we would like to investigate, but being unresponsive for several seconds is definitely a bug. Are you working on some large project with a lot of assets?

    I remember doing a fix for something similar few months ago, not sure on which release it landed though... Can you open a bug from the bug reporter including at least your current projectSettings and the preset you are trying to apply to it?
     
  20. JPFerreiraVB

    JPFerreiraVB

    Joined:
    Sep 18, 2017
    Posts:
    39
    I did already open the bug. The preset fails to apply when we have a icon on the default icon property. If i remove any image reference on the player settings, it works.
     
  21. lindsaytalbot

    lindsaytalbot

    Joined:
    Sep 11, 2015
    Posts:
    28
    I have a bug where any time I set a preset on a transition it effectively deletes that transition. It shows as being there until either you click onto another transition or close and re-open the animator. Tried different animations, transitions and presets. Very annoying. Unity 2018.2.19f, Pro Skin
     
    Last edited: Feb 13, 2019
  22. lindsaytalbot

    lindsaytalbot

    Joined:
    Sep 11, 2015
    Posts:
    28
    Okay I've managed to figure out the cause of the issue. The presets only work for transitions with the same destination as the original. So if I make a transition from Anim1 to Exit, I can then create a preset based on that and use it for for Anim2 to Exit. But if I try and use that preset from Anim3 to Anim4 Unity moves the transition to go towards Exit as was saved in the preset. If I create a preset that targets a node other than Exit and then try and use it in another animator the transition is deleted but remains in the list as a bad references.

    This effectively makes animation transition presets useless when it could otherwise be kind of useful.
    At the very least you should be able to group edit transitions so I can set timings and conditions for a bunch of animations at the same time
     
  23. Fanakartal

    Fanakartal

    Joined:
    Apr 2, 2013
    Posts:
    3
    Hi there,
    Is there any way to use presets to change child gameobject's attributes with only single parent preset?
    For example, in my case; I have a human model with rig and I want to change his fingers' positions and orientations. One by one I changed all of the fingers' transforms and save the presets of all of the fingers to use them on another model's hand. If the preset allows a parent preset with the selected attributes of the children included, say "transform", and save it as a whole preset, say "left_hand.preset" it would be very helpful. It is very time consuming thing to control if any of the finger rig's positions and rotations are correct or not for both of the hands.
    If there is not a feature like this, I think that could be cool to add this in future versions like "nested presets" or such.
    thanks for the presets feature by the way, it is very helpful even as it is.
     
  24. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    Hi Fanakartal,
    Would you like to share that model and the script you are using with me, maybe I could take some time to play with it and figure out some easier way to do it?
    Some thought that came in mind: Do you need to save those values somewhere for later use, or are you just trying to copy/paste them from one object to another?
    If you just need to copy/paste the value and don't want to store anything, I'd go directly with a script going through both transform hierarchy and using CopySerialized to apply one transform value to the other: https://docs.unity3d.com/ScriptReference/EditorUtility.CopySerialized.html
    If you want to keep a copy somewhere, I'd go with a Prefab instead of a Preset. Prefabs have the advantage to keep the full serialization of a GameObject hierarchy with all its components. Maybe you could create a Prefab out of your base hierarchy and then connect each other hierarchy to this Prefab, revert values, disconnect them, and so on, so maybe you can trick the system to apply one full hierarchy value to another in a very easy way.
     
  25. TimHeijden

    TimHeijden

    Joined:
    Mar 5, 2015
    Posts:
    34
    Hey Bastien, is there any update on this? Just checked this in 2019.1.0b7 and it's still not in there.

    Fixing this would actually make that "default" setting usable for UI, because right now you're better off not using it for sake of consistency.
     
  26. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    The fixes made their way into 2019.2.0a4, it required some changes in the Undo system that was not handling Presets and RectTransform creation very well which unfortunately prevented us from landing that fix sooner.
     
  27. TimHeijden

    TimHeijden

    Joined:
    Mar 5, 2015
    Posts:
    34
    Good to know it's fixed in the future at least, thanks :)
     
  28. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hey, presets have been a godsend since I updated to 18.3. One thing though, it'd be nice to be able to exclude some attributes. I'm using it to set up a heap of animation @Fbx files and it kinda messes up animation names and Start/End ranges. At the moment I just fix those up and it's still wayyyyy better than having to set every other aspect.
    Thank you!
     
    laessnb likes this.
  29. Fanakartal

    Fanakartal

    Joined:
    Apr 2, 2013
    Posts:
    3
    Hi Bastien, I cannot share actually a script because there is none. I have a 3d human model and I am changing his fingers' positions to set them like holding the VR controllers. And then, I am doing the same thing for a female model. I have no modeling experience so I need to do it in Unity. Surely I can use a code, but I do not have much time to think on it because of my constraints and I thought if presets can work nested, it can be a good thing to use. I only copy the values to another model but the project can mandate me to change the models; then I need to do everything all over again.

    So for your answer's last part, I guess that can be used. I make a prefab out of the hands, and paste it into the other model's hands. But the model is by on its own also a prefab, so I need to change model's prefab also. Maybe I will need to use the original model afterhand, so maybe I need to do another prefab for the model out of the original prefab. Did I understand you correctly for the last part, right?
     
  30. NGC6543

    NGC6543

    Joined:
    Jun 3, 2015
    Posts:
    228
    What is the best workflow to use Preset for automating the asset import process?

    I created some presets for textures and models, but couldn't find a way to utilize it with a custom script.
    I'm trying to automate the import process using AssetPostprocessor, and switch import settings using presets per asset(something like if the assetpath contains 'transparent', 'alpha', 'overlay' or something, use a preset for transparent texture).

    I saw the "Asset Auditing" manual from Unity Documentation, but the example shows 'hard-coded' settings. This method doesn't look flexible.
    With this BEAUTIFUL Preset system, asset importing automation could be a lot flexible.
    Can anyone give some advice or direction to do it?
     
    Last edited: Apr 22, 2019
  31. NGC6543

    NGC6543

    Joined:
    Jun 3, 2015
    Posts:
    228
    Ah, I almost forgot. I created a preset from a TextureImporter and noticed that the 'Alpha Is Transparency' option stays unmodifiable even if the 'Alpha Source' is set to 'Input Texture Alpha' or 'From Gray Scale'. Happens on Unity2019.1.0f1. Is this an intended behaviour?
     
  32. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    This on our roadmap, not sure when it will land in Unity yet, but being able to exclude attribute was part of our initial design of Presets, so is definitely something that is coming.
    There are also some work and exploration done around the Animation import in the ModelImporter to make it easier to iterate with them in a project which would save that kind of animation renaming problems with Presets.
     
    petey likes this.
  33. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    Using AssetPostprocessor is the correct way to do it. I've implemented a bunch of default methods myself for some local testing but everything was in fact still very hardcoded...
    We are working on a better implementation of the PresetManager that would allow you to set defaults based on some search filter. That would do natively exactly what you are doing here.
    At the moment I would suggest you use a ScriptableObject to keep a list of all your Presets and select them from AssetPostprocessor.OnPreprocessAsset based on your asset path/name. You can apply them using preset.ApplyTo(importer).
    Thanks for pointing out that page! I'll add a note on our team board to look into it and update it with Presets. We made them to address that exact problem after all ;)
    This definitely looks like a bug, if you could report it from the bug reporter that would help us track it nicely.
     
    NGC6543 likes this.
  34. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    I think that would be easier to manage with a script but yes, you got the overall idea, prefabs are a bit out of my expertise though, so even if I got some ideas on how that should work, I may be mistaken here...
     
  35. NGC6543

    NGC6543

    Joined:
    Jun 3, 2015
    Posts:
    228
    I've already created a report on this.
    Case ID : 1147407

    And I appreciate for your kind reply. I'll try the Scriptable Object method for now!
     
  36. rfadeev

    rfadeev

    Joined:
    Oct 1, 2013
    Posts:
    21
    Is there a way to get preset target type as an System.Type object? Currently there is only Preset.GetTargetFullTypeName which returns type name as a string (it would be really great to have Preset.GetTargetType which returns System.Type).

    I tried to use approach described here http://answers.unity.com/answers/239152/view.html and it worked until I added assembly definition file to the project and Assembly.Load started to fail load types from my own namespace.
     
  37. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    Not at the moment. Some types available in Preset are internal, not exposed in C# and the only System.Type they would refer to would be UnityEngine.Object, which is wrong and unreliable... We are aware that it is a bit cumbersome and would like to fix it but this kind of changes have a lot of side effects and will take some time...
    A quick example would be the ModelImporter. We have 3 different implementations of if under the hood and you can notice that creating a Preset out of an FBX file will give a UnityEditor.FBXImporter instead of UnityEditor.ModelImporter. However, the UnityEditor.FBXImporter class does not exist in C# and exposing it is breaking some other API we need to fix first. The same problem is present for a dozen classes we can create Preset from and are not exposed for some historical reason.

    That seems a bit strange to me, while Type.GetType may fail with Unity types (because it may not exist like for the FBXImporter), it should always work for your assemblies.
    Can you report a bug from the BugReporter, joining your project? I'll be glad to have a look at it and either figure out a solution you can use or fixing what is broken on our side.
     
  38. rfadeev

    rfadeev

    Joined:
    Oct 1, 2013
    Posts:
    21
    Hello @bastien_humeau,

    Thank you very much for the explanation and prompt answer! Interesting, those internal types would have UnityEngine.Object type, but what would Preset.GetTargetFullTypeName return for them?

    I've submitted the project, case number is 1187183. I'm pretty sure something is broken on my side as the link I posted feels to be hacky way to get the type. I have a feeling that adding assembly definition to folder where code calling Type.GetType resides is the problem as probably Assembly.Load would look only into files present in that folder exactly due to assembly definition file added. I also looked into TypeCache but seems it's not suitable to solve the problem.
     
  39. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    Looking a bit at the bug and code, I'm not sure if that's broken on your side or if that's a problem with the assembly loading when dealing with asmdef, but that's a bit outside of my area so I'll let the scripting team look at it in detail and decide what to do.

    Regarding the using of the System.Type itself in your project, if you don't need explicitly a System.Type and are fine comparing string, GetTargetFullTypeName should be enough. In the case of an Internal Unity type not exposed in C#, this method will return our internal c++ namespace and name, which usually fit other C# implementations (as mentioned in my previous answer, the FBXImporter preset will gives you UnityEditor.FBXImporter, which should be the real C# name once we are to expose it).
     
  40. rfadeev

    rfadeev

    Joined:
    Oct 1, 2013
    Posts:
    21
    Many thanks for taking a look at the project! Really appreciate that.

    You are right, comparing preset target full type names should be fine. I changed the code this way and seems fine. Unfortunatelly I cannot recall why initially I decided to use System.Type instead of full type name for that purpose.
     
  41. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    @bastien_humeau about still not having partial presets, why can't the Preset UI not just work similar to either Prefab UI (which allows marking / unmarking of specific properties) or Animation UI (which does the same, allowing specific properties to be keyed/unkeyed)?

    I'd like to just rightclick on a property when the preset is selected, click on "exclude" and be done ...

    Currently, presets for a lot of things are not usable - e.g. UI Text, as the text field is always changed whenever a preset is applied. Only workaround is to wrap everything in Prefabs and apply the presets to prefab parents.
     
    kilik128 and petey like this.
  42. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    That's what we are working on right this instant! Trying hard to get it into 2020.1.
    There is a lot of work to do on most Inspectors to make them work properly with that feature, and while we are focusing on the AssetImporters at first, we are aware some other Inspectors will not behave properly (did anyone notice that some Prefab control does not work at all on some inspectors or some properties? Camera, I'm looking at you...).
    We want to release the feature anyway so it can be used in most cases and will fix all Inspectors as soon as possible, based on the one we are aware of and the bug report that users will send to us.
     
    NGC6543 and petey like this.
  43. Brad-Newman

    Brad-Newman

    Joined:
    Feb 7, 2013
    Posts:
    185
    @f1ac
    Some code for doing something like this for in Unity 2019.3:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEditor.Presets;
    4.  
    5. public class ApplyProjectPresets : EditorWindow
    6. {
    7.     public Preset playerSettingsPreset;
    8.  
    9.     [MenuItem("Presets/Presets Window")]
    10.     public static void ShowWindow()
    11.     {
    12.         GetWindow(typeof(ApplyProjectPresets));
    13.     }
    14.  
    15.     public void OnGUI()
    16.     {
    17.         GUILayout.Label("Player Settings", EditorStyles.boldLabel);
    18.  
    19.         EditorGUILayout.BeginHorizontal();
    20.         playerSettingsPreset = EditorGUILayout.ObjectField(playerSettingsPreset as Preset, typeof(Preset), false) as Preset;
    21.         EditorGUILayout.EndHorizontal();
    22.  
    23.  
    24.         if (GUILayout.Button("Apply Player Settings Preset"))
    25.         {
    26.             Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings");
    27.             playerSettingsPreset.ApplyTo(Selection.activeObject);
    28.         }
    29.     }
    30. }
     
  44. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
  45. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    How do you use the filter? Do you have any examples? Can you filter by folder?
     
  46. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    The documentation is not up to date yet, but the filter is working the same as the search in the Project Browser view.
    You can basically search on "_Normal" to find any asset of the corresponding importer type that contains "_Normal" in its name.
    In 2020.1 we are adding a Glob search in that filter that will allow you to filter based on specific paths and that is case sensitive. That will allow for more specific searches like `glob:"**/Characters/*.(fbx|FBX)"` that will match the filter to any .fbx or .FBX files inside a folder named Characters (and as a bonus, that will also allow you to search with this pattern in the Project Browser view!)
     
  47. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    Thanks for the quick reply. Maybe the folder selection could be added to the Preset Manager directly?
     
  48. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    We added it this way at the moment so everyone can set exactly what they want (some users don't want to filter on folders but with some naming conventions instead, or both at the same time, or based on other conventions we don't/can't know).
    Still, I agree folder seems like a basic need and having it by default would be nice, but it implies adding a large dropdown menu in this UI that is already a bit small for all the information it contains... We will look into it and see what improvements we can do on the usability side!
     
  49. laessnb

    laessnb

    Joined:
    Jun 10, 2014
    Posts:
    101
    I'm very much looking forward to this, because the very first use case that got me all excited about presets was swapping my various Button components from Color Fade to Sprite Swap (along with all the various button states), but applying my custom Button preset blew away the event handling setups I had carefully wired up as well as the target graphic references. Same will happen with any number of other components that essentially present sets of "should be shared consistently" vs "should only be per instance" inspector fields, but all-or-nothing presets don't respect this dichotomy.
     
    fherbst likes this.
  50. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    Everything already landed around 2020.1.0a15 so it should be part of the current alpha release if you're willing to give it a try.
    Any property in the Preset inspector can now be right-clicked and excluded from the Preset. Its value will be kept in the UI but not used anymore when applying it. right-clicking again on the same property allows to re-enable it. Any disabled property will disable its child (thinking about arrays or struct for example) but you can then reactivate only one of the child by selecting this one directly.
    You can also right-click on the Preset header to exclude/include all properties at once.
     
    laessnb likes this.