Created
August 12, 2025 14:25
-
-
Save adammyhre/b7b7cda45097114a118a547a3ddb7afb to your computer and use it in GitHub Desktop.
Automating creation of a custom Unity Project Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
############################################## | |
# make-template.sh | |
# | |
# This script packages a Unity template for local use | |
# in Unity Hub's ProjectTemplates folder. | |
# | |
# How it works: | |
# 1. Prompts for the full Unity version (e.g., 6000.1.15f1 or 6000.1.0b12). | |
# 2. Deletes ProjectVersion.txt from the package folder if it exists. | |
# 3. Creates a .tgz archive from the 'package' folder. | |
# 4. Moves the archive into the correct Unity ProjectTemplates folder | |
# under C:\Program Files\Unity\Hub\Editor\<version>\Editor\Data\Resources\PackageManager\ProjectTemplates | |
# | |
# Requirements: | |
# - Run this script in Git Bash with Administrator privileges. | |
# - 'tar' command must be available (included with Git Bash). | |
############################################## | |
TEMPLATE_NAME="com.unity.template.malevolent.tgz" | |
SRC_DIR="package" | |
require() { command -v "$1" >/dev/null 2>&1 || { echo "Error: $1 not found in PATH"; exit 1; }; } | |
require tar | |
if [[ ! -d "$SRC_DIR" ]]; then | |
echo "Error: '$SRC_DIR' directory not found in $(pwd)" | |
exit 1 | |
fi | |
read -rp "Enter full Unity version (e.g., 6000.1.15f1): " UNITY_VERSION | |
if [[ ! "$UNITY_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+[a-z][0-9]+$ ]]; then | |
echo "Error: version must look like '6000.1.15f1' or '6000.1.0b12'" | |
exit 1 | |
fi | |
# Path to Unity's ProjectTemplates folder (Git Bash/MSYS format) | |
TARGET_DIR="/c/Program Files/Unity/Hub/Editor/${UNITY_VERSION}/Editor/Data/Resources/PackageManager/ProjectTemplates" | |
if [[ ! -d "$TARGET_DIR" ]]; then | |
echo "Could not find: $TARGET_DIR" | |
echo "Available Editors under /c/Program Files/Unity/Hub/Editor:" | |
ls -1d "/c/Program Files/Unity/Hub/Editor"/* 2>/dev/null || true | |
exit 1 | |
fi | |
# Remove ProjectVersion.txt if present | |
PROJECT_VERSION_FILE="${SRC_DIR}/ProjectData~/ProjectSettings/ProjectVersion.txt" | |
if [[ -f "$PROJECT_VERSION_FILE" ]]; then | |
echo "Removing $PROJECT_VERSION_FILE..." | |
rm -f "$PROJECT_VERSION_FILE" | |
else | |
echo "No ProjectVersion.txt found, skipping removal." | |
fi | |
# Create the .tgz | |
echo "Creating archive: $TEMPLATE_NAME from '$SRC_DIR'..." | |
tar -czf "$TEMPLATE_NAME" "$SRC_DIR" | |
# Move to Unity's ProjectTemplates folder | |
echo "Moving $TEMPLATE_NAME to:" | |
echo " $TARGET_DIR" | |
mv -f "$TEMPLATE_NAME" "$TARGET_DIR/" | |
echo "Done." | |
echo "Template installed to: $TARGET_DIR/$TEMPLATE_NAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Git Bash script to package a Unity template and install it into the correct Unity Hub ProjectTemplates folder.
Prompts for the full Unity version (e.g., 6000.1.15f1, 6000.1.0b12), removes ProjectVersion.txt from the template package if present, creates a .tgz archive from the 'package' folder, and moves it into the corresponding ProjectTemplates directory inside the Unity installation. Must be run as Administrator in Git Bash.