Unity : Custom Templates in 5 Minutes

Unity : Custom Templates in 5 Minutes

I’ve recently gotten into VR development and it can be incredibly tedious to start from scratch with every single project. You have to install a few packages and customize a whole bunch of settings to get it to work correctly. Instead of wasting 30 minutes setting everything up for each new project, creating your own custom project template is a great way to save time.

Side note: If you’re just getting into VR, I’d advise practicing starting from scratch a few times just so you can get familiar with the packages, controllers and settings. This will save you a ton of guess work in the future. If you would like a guide to setting up a VR project in Unity, it can be found here.

Step 1: Create a new project (Skip this step if you're coming from VR Custom Templates)

This is about as easy as it gets. Create a new project and start loading it up with everything that you want in your future custom template.

Make sure to get all the packages (like Cinemachine or XR Interaction Toolkit) and assets (music, models, ect) that you want in the project now.

You can always redo the process later, but it can be a bit of a pain, so make sure to go over your checklist of what you want in your template.

Step 2 : Locate your Project Template Folder

The path you’re looking for should be similar to the one listed below

Unity\Hub\Editor\2020.3.6f1\Editor\Data\Resources\PackageManager\ProjectTemplates

Side Note : The Unity version after Editor should be the same that you’re using for your template

You'll be looking for a folder in Unity that looks like this.

This folder contains all the templates that Unity Hub uses to generate new projects. We’ll be using one of these to make our own.

Step 3 : Open Up a Project Template

Project templates are zipped up as a .tgz . You can open them with various programs like 7-zip, winzip, ect. I’ve always just gone with 7-zip which can be found here.

Inside you’ll find a folder called package and when you click it, you’ll find this! This is what we’ve been looking for. Make sure to go back a level and drag and drop the package folder out into your Project Template folder.

It will look like this if you did it correctly

Step 4 : Editing the Package Folder

Locate the package.json file. You’ll need to open it up using an editor. Visual Studio, Notepad or whatever coding dojo you fancy.

Once it’s open we’ll need to change some things to help customize our template.

Underlined in the image above will be the lines that we’re changing.

name : This field you need to make sure you keep the convention that Unity has established.

example:

“name”: “com.unity.template.universal

would become 

“name”: “com.unity.template.awesometemplate

 

displayName :  You can change this to whatever you want. It is what you’ll see in the Unity Hub when we’re done. If you don’t change it, you’ll end up with multiple templates with the same name.

 

description : This helps describe what the template is. It’s nice to keep things organized, so make sure the description makes sense to future you 5 years from now. 

Boom. That’s it. Save and exit package.json

Step 5 : Copying Your Project to the Template Folder

You might need to enlarge this

First: We’ll want to go into the ProjectData~  folder that’s located int the package folder. From there, we can delete the Assets, Packages and Project Settings.

Second: We’ll want to locate the project that we wish to make a template out of. Then we copy the Assets, Packages and Project Settings into the ProjectData~ folder.

Third: We need to go into the ProjectSettings of the folder we just copied. Inside will be a folder called ProjectVersion.txt  . If we do not delete this file, the template will not work.

Step 6 : Create TGZ File

7-Zip comes back to save the day for us here. We’ll be using it to create the TGZ file for Unity Hub to use. Right click on package and go to 7-Zip. Choose “add to archive”.

(If you don’t see 7-Zip when you right click the package folder, you can also open 7-Zip and locate the folder and right click it to do this step.)

At the top it will ask for a name. Use the naming convention from before and finish it with .tgz

Example: com.unity.template.awesometemplate.tgz

Once the new .tgz file is created, make sure to delete the old package folder. If you do not do this, it can cause errors.

Step 7 : Restart Unity Hub and You're Done!

Restart Unity Hub and start up a new project. You should see your template as an option to choose from.

Congrats! You just saved a bunch of time on future projects.

Cheers!!!