Each time I open a new project I get by default Visual Studio Code package 1.2.0. But that one has problems with IntelliSense. So I manually change to Visual Studio Code Editor 1.1.2 which works with IntelliSense. But I would like to avoid doing that each time I make a new project. Can it be avoided?
Just a thought, but I wonder if it’s possible to make your own project templates?
In the same way there are “3D” and “3D With Extras” templates on the Unity Hub, it would be good if it was possible to make your own with whatever packages you wanted to include.
But I’ve no idea whether that’s already possible or not.
CityGen3D:
Just a thought, but I wonder if it’s possible to make your own project templates?
In the same way there are “3D” and “3D With Extras” templates on the Unity Hub, it would be good if it was possible to make your own with whatever packages you wanted to include.
But I’ve no idea whether that’s already possible or not.
There isn’t, but that’s been a requested feature by me and a couple others.
1 Like
Ryiah:
Looking into it, apparently this is the process and… uh…
Maybe it needs a bit of UX work.
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](https://github.com/rfadeev/pump-editor/blob/master/Editor/ProjectTemplates/UnityProjectTemplateWindowMenuItem.cs) I created to open that window. I also added my own "Save Project As Template" [editor window](https://github.com/rfadeev/pump-editor/blob/master/Editor/ProjectTemplates/SaveProjectAsTemplateEditorWindow.cs). Main differences from Unity's built-in one:
- By default opens save template folder panel in **ProjectTemplates** in Unity installation folder (for Unity version you use to open editor window)
- Removes "ProjectSettings/ProjectVersion.txt" file on template creation.
- Allows to select default scene via object field so no need to type in scene path.
- 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.
3 Likes
Ryiah
May 25, 2020, 11:51pm
6
Choose the base template that you want everything to be built around and extract it into a folder somewhere. From there open package.json contained within the base folder of the template files and change name to a unique identifier for your organization and displayName to a the text you want visible in Unity Hub. Once you’re done save and close the file.
Open manifest.json stored under ProjectData~\Packages. Add any custom packages by name and version. Just as an example if you wanted v2.0.1 of the Google VR package for iOS you’d add "com.unity.xr.googlevr.ios": "2.0.1" Once you’re done save and close the file.
Finally we need to recompress everything. With 7-zip (or equivalent tool supporting tar) create a tar of the base folder and all of its contents into a file named after the unique identifier you specified in package.json. Once you’ve created it you need to gzip the tar. Once you’ve recompressed it move the file into the projects template folder appropriate to the location of your editor and version. I screenshotted the location of mine because ICODE can’t handle the full length properly.
Thanks for letting me know there is a way to do it within the editor.
1 Like