Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Will we be able to define our own Templates?

Discussion in 'Unity Hub' started by Schneider21, Jan 24, 2018.

  1. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    2,914
    It'd be great if we could set up our own templates, so that we can jump-start new projects to match our own workflows.

    For example, if I always use a certain set of assets, with a couple of prefabs for customized character controllers, quality settings, etc... I can start a new project with the Schneider's Startup template and have a few days work already done for me.

    This is the value I'd find in templates. Getting a basic 2D/3D setup I still have to do a lot of work for isn't all that exciting to me.
     
  2. massivebacon

    massivebacon

    Joined:
    Apr 24, 2014
    Posts:
    15
    Seconding this. I'm thinking especially for easily scaffolding projects, but also being able to more easily facilitate modding workflows that use the Unity editor for their main modding platform. Things like Sky Rogue, Cities Skylines, and others would be much benefited from being able to just provide a Unity template that people can use to easily get started modding without needing to import additional packages and configurations.
     
  3. Narv

    Narv

    Joined:
    Apr 4, 2013
    Posts:
    5
    Seems like the best way for this may just be to setup a project how you want the template to be. Then either from inside Unity or from the hub itself (having to save and close the project most likely) have a "Create Template" option that will create a custom template off the current Unity project.
     
    TaleOf4Gamers likes this.
  4. BackwoodsGaming

    BackwoodsGaming

    Joined:
    Jan 2, 2014
    Posts:
    2,205
    I already do this. The problem is the project may contain old versions of the assets whereas I see the template maybe installing the current version of the asset. I literally just found out about the hub beta, so I'm not sure if that is the case but that is how I hope/assume it works.

    I also would like to jump on the bandwagon with this request. It would be awesome if we could setup our own templates to use here.
     
  5. SpencerMowrey

    SpencerMowrey

    Joined:
    Nov 3, 2016
    Posts:
    5
    This has my vote!
     
  6. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    114
    By looking a bit around the Unity folders I found this folder inside latest beta version : Editor/Data/Resources/PackageManager/ProjectTemplates
    These are the templates used by Unity Hub. You can just duplicate one of the folders in there and update the package.json file to have the name and description you want. That will allow you to have a custom template.

    It's obvious that this is not the official way nor something that would survive an update but it's just to give you an idea of how it works at the moment.

    I'm just wondering if it will change because with this solution it means that templates are tied to Unity's version and that you would need to open Unity then the package manager to update them which is not great in my opinion. Maybe by having the package manager inside Unity Hub would help greatly ?
     
    BackwoodsGaming likes this.
  7. the_natbird

    the_natbird

    Unity Technologies

    Joined:
    Jul 7, 2017
    Posts:
    2
    Yes! I think this will be important for streamlining and improving the Unity user experience! We have a bunch of plans for expanding the template system, including the ability to add and share custom user templates. Keep your eyes open for template updates in future Unity updates!
     
  8. StephenHodgson-Valorem

    StephenHodgson-Valorem

    Joined:
    Mar 8, 2017
    Posts:
    148
    Def a great idea. Any update on this?
     
  9. throzen

    throzen

    Joined:
    Jun 11, 2015
    Posts:
    6
    I hate to revive old threads, but this seems like the only one regarding this specific topic, so I'll post here and refrain from a new thread to keep things bundled.

    Has anyone found a way to add their project as a new template?

    Obviously dzamani's idea seem to be the right direction, and that is what I have been trying before finding this thread, but there seems to be an issue when doing that. At least I am having one:

    As soon as the "name" in your newly created template's manifest is set (or changed, if you have copied one of the other templates) an error occurs when choosing that template for a new Unity project:
    "Failed to resolve Project template: the folder or package [XYZ] could not be found"

    I tried naming things equivalent to how unity does, so folder and "name" in the manifest are the same, Folders that are copied to the template folder are the same... no difference as far as I can tell except for the manifest name. It really seems to be the name defined in the manifest that is the deciding factor. But it doesn't recognize the name of my template as an existing folder/template or whatever.

    Has anyone sucessfully done this and can tell me if I am missing something?
     
  10. Mickey_omar

    Mickey_omar

    Joined:
    Jan 7, 2017
    Posts:
    8
    Any news?
    I created a template and would like to understand more about the package.json file. What I want is to open a certain template directly in Android platform. I added this line "buildTarget":"Android" at the end of the json file and nothing happened. Any hints? or this is not even possible?

    Also, is there a way to include folders other than Assets, ProjectSettings and Packages? I would like to include the SteamVR 2.0 generated action json files rather than generating them every time I create a new project.

    Thanks a lot guys!

    EDIT:
    I tried adding the Library folder and it worked like a charm for the "Android part". Not sure what really solved it, the "buildTarget" or the "Library". Anyway, I did both in case someone wants to try.

    Have a nice day
     
    Last edited: Dec 4, 2018
  11. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    335
    Add me to those wanting to create our own project templates @the_natbird

    The first one I'd make is a cleaned out 3D project:
    • Without these packages: Advertisement, In App Purchasing, Analytics Library
      • These have to be removed one...by...one...ugh
    • With the following packages added
      • ProBuilder
      • Asset Bundle Browser
      • Post Processing
      • FBX Exporter
    • No Sample Scene
    • Player Settings
      • Rendering Color Space: Linear
      • API Compatibility: 4.x
      • Scripting Runtime: 4.x Equivelant
        • this always has to be changed and requires restart

    Then I'd make another one like the above that adds the following packages along with Vegetation Studio Pro:
    • Mathematics
    • Collections
    • Burst
    • Jobs
     
    JBAkka likes this.
  12. JBAkka

    JBAkka

    Joined:
    Dec 14, 2018
    Posts:
    1
    Thanks, MrG. Almost exactly what my team needs, too. So +1 on this.
     
  13. throzen

    throzen

    Joined:
    Jun 11, 2015
    Posts:
    6
    Hey guys.
    After I updated to Unity 2018.3.5 today (from 2018.2.16 previously) this seems to actually work if you are willing to go through the following steps (and not wait for unity to enable it though some simple interface of theirs):
    1. Go to your unity installation path and navigate to where the templates are saved. in my cast for example that is:
      C:\Unity\Unity2018.3.5\Editor\Data\Resources\PackageManager\ProjectTemplates

      From here we want to mimic the way the other tempates are defned. easiest way is to do the following
    2. Copy any of the other template folders and rename the end of it to whatever you want:
      E.g.: com.unity.template.mytemplate
    3. Inside that folder, you need to replace the Assets, Packages and Project Settings folders with the ones you want your template to have
      1. Go inside the ProjectSettings folder and delete the text files such as ProjectVersion.txt, so you only have all the .asset files left in it
    4. Go back to your com.unity.template.mytemplate folder and open the package.json file
      1. change the "name" attribute to match your template fodler name, i.e. com.unity.template.mytemplate
      2. change "displayName" to what you want it to say in the dropdown menu when choosing a template for a new project
      3. change the "defautScene" to the path of the scene you want to be opened by default when choosing your template. All relative to the newly added Assets folder, so for example "Assets/Scenes/MyStartingScene.scene"
      4. The rest is optional basically
    I tried that out yesterday and was able then to choose my template and it started everything as intended. No more error, like I described a while back in this thread, so they seem to have changed/fixed something with the Engine upgrade. No Idea in which version exactly this started to work, but with the currently newest Version (2018.3.5f1) I was able to do it.

    EDIT: it seems that your project version, as defined in the json file, needs to have 3 digits devided by a point, so 1.0.0 for example. That seems to be a convention for the templates, and the Unity launcher will not budge if you do not abide by that. I had 2 numbers at first and I would see my template in the launcher but get errors when trying to open a project using it

    cheers
     
    Last edited: Feb 26, 2019
  14. MrMatthias

    MrMatthias

    Joined:
    Sep 18, 2012
    Posts:
    179
    instead of copying the assets from a template it would also be nice to provide a custom repository for packages, so i can simply provide a packages configuration for the templates
     
  15. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    34
    @the_natbird It's been over a year now, what's taking so long?
     
    misabiko and KrzysztofX10 like this.
  16. swanickj

    swanickj

    Joined:
    May 15, 2019
    Posts:
    23
    I hereby bump this. I'd be very happy for a custom template workflow.
     
    KrzysztofX10 likes this.
  17. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    612
    Just tried this based on @throzen's post above, but in Hub 2.1.1.
    Some things have changed, but baseline is: it is still possible to manually create your own templates.



    Unity has packed their templates into tgz files by now. 7zip can open and modify these. I found it easiest to just rename one of the default templates, open it in 7zip and copypaste my correct files in, but you can also just first create a tar archive, then gzip it, and rename the result from tar.gz to tgz.
    There's one thing you must do before copying one of your projects Assets/ProjectSettings/Packages folders in: delete the ProjectSettings.txt, otherwise there's gonna be an error.
     
    throzen likes this.
  18. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    780
    The problem is that we have to do it on each Unity Editor version... There should be some easier way to do this.
     
  19. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    612
    Definitely! Just wanted to update the information available with the current state.
     
    swanickj likes this.
  20. mekartikshah

    mekartikshah

    Joined:
    Jan 10, 2017
    Posts:
    54
    Bumping this, previous ways by @throzen is nice, but how can I share those templates with team members?
     
  21. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    612
    Currently you have to copy it manually to everyone's Editor templates folder. For each Editor installation.

    I really hope there will be a proper "templates are packages" or so way where we can just point the Hub to a package registry or even a network drive folder where templates are found.
     
  22. AccentDave

    AccentDave

    Joined:
    Nov 16, 2015
    Posts:
    43
    Seems like someone could write an Editor script 'Install Templates' which lets you choose them and installs for the current version of Unity you are using, or maybe scans for other installs and gives that option.
     
  23. AccentDave

    AccentDave

    Joined:
    Nov 16, 2015
    Posts:
    43
    You don't need to tgz your files, you can dump them in like it was in 2018 and it will work
     
    fherbst likes this.
  24. rfadeev

    rfadeev

    Joined:
    Oct 1, 2013
    Posts:
    19
    After searching Unity C# reference for a method to reopen the project, I accidentally came across method to save project as template: EditorUtility.SaveProjectAsTemplate which is called from internal Unity editor window ProjectTemplateWindow. By using that via reflection, I got a chance to play around with project template creation via Unity API and would like to share my findings. All below was tested with Unity Hub 2.3.0 and Unity 2019.3.0f6.

    EditorUtility.SaveProjectAsTemplate creates project template at target path passed. Created template consists of Assets, Packages and ProjectSettings folders and package.json. Template is ready for use in Unity Hub so placing it to your Unity install folder would make it appear in list of templates. For example like "UNITY_INSTALLS_PATH\2019.3.0f6\Editor\Data\Resources\PackageManager\ProjectTemplates\MyTemplate". Template package.json created by EditorUtility.SaveProjectAsTemplate always has the same structure presented below (values for keys are added as an example):
     {
    "name": "com.rfadeev.template.test",
    "displayName": "Test Display Name",
    "description": "Test Description",
    "defaultScene": "Assets/Scenes/MyScene.unity",
    "version": "1.0.0",
    "category": "ProjectTemplate",
    "dependencies": {}
    }

    Values for keys name, displayName, description, defaultScene and version can be empty strings. Value for category must be always ProjectTemplate. Value for dependencies can be empty object. If create project with EditorUtility.SaveProjectAsTemplate and all parameters passed to method are null, Unity would create valid template which Unity Hub can recognize (package.json fields except category would be empty strings/empty objects). If set name value in package.json to be not empty string (like "com.rfadeev.template.test") while other fields are empty strings/empty objects, Unity would fail to create project from template with "Failed to resolve project templates: Package [com.rfadeev.template.test] cannot be found". To fix that error, need to set version in package.json. Once set, Unity would still fail to create project but with different error: "Failed to resolve project template: The file [ProjectSettings/ProjectVersion.txt] must be omitted". After file mentioned is removed from template folder, Unity can create project from template normally. displayName, description and defaultScene seem to not affect project creation from template.

    Template folder name in ProjectTemplates folder can be different from template name in package.json and Unity Hub would still normally create project from template. Name in ProjectTemplates affects only templates sort order in the "Create a new project with Unity 2019.3.0f6" menu. displayName, description from package.json are used to display template button in that menu. If description is not empty string, round "i" button is shown on the template button in Unity Hub.

    defaultScene in package.json is scene Unity would open after project is created from template. Format of that field is full scene file path in Unity project folder like "Assets/Scenes/MyScene.unity".

    If you would like to open Unity built-in ProjectTemplateWindow, to play around with template creation yourself you can use menu item I created to open that window. I also added my own "Save Project As Template" editor window. Main differences from Unity's built-in one:
    1. By default opens save template folder panel in ProjectTemplates in Unity installation folder (for Unity version you use to open editor window)
    2. Removes "ProjectSettings/ProjectVersion.txt" file on template creation.
    3. Allows to select default scene via object field so no need to type in scene path.
    4. Allows to replace template when saving. By default EditorUtility.SaveProjectAsTemplate does not remove any files in target folder which can be undesired if some of the files were removed from the project template is created from (when iterating on template creation).

    Last but not least: when creating project from template, Unity uses several sources to determine packages to be present in the created project. First, it's dependencies from template's package.json. Second, it's packages in template Packages folder (both local package folders and Packages/package.json file). Third, Unity install package manager's manifest.json (can be found in "UNITY_INSTALLS_PATH\2019.3.0f6\Editor\Data\Resources\PackageManager\Editor"). This file has defaultDependencies which enforces all created projects (including projects created from templates) to have packages listed there. While this can be not expected behaviour, I did not find a way to ignore packages from defaultDependencies when creating project from template via Unity API. Workaround I see is changing manifest.json file but this affects all new projects created.

    Hope this helps with creating your custom project templates.
     
    Last edited: Mar 7, 2020
    mattnewport and fherbst like this.
  25. BdarVirtu

    BdarVirtu

    Joined:
    Mar 26, 2020
    Posts:
    3
    Hi! This all was very helpful, thank you. But my Unity template makes Unity crash in any other pc besides my own. Could someone please point me to a solution?
     
    Last edited: Apr 2, 2020
  26. Menyus777

    Menyus777

    Joined:
    Jun 11, 2017
    Posts:
    11
    Can we get an offical update on this?
     
    atranson likes this.
  27. BdarVirtu

    BdarVirtu

    Joined:
    Mar 26, 2020
    Posts:
    3
    Figured it out: do NOT delete the main camera from the Sample scene
     
  28. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    612
  29. TheUninvited

    TheUninvited

    Joined:
    Jun 22, 2018
    Posts:
    31
    For you who struggling to do this, i just made a video if it helps:
     
    Menyus777 and MrBuBBLs like this.
unityunity