Dec
7
2023

UnityHub: Add support for custom project title (instead of folder name) or use ProductName

This request has been open since 2018..
https://forum.unity.com/threads/renaming-projects.514061/

So had to test it myself and seems to be really simple
(*** as a proof of concept, i don’t know it the Title value affects something else)

Steps:

  • Unpack app.asar from Hub folder (using 7zip Asar plugin https://www.tc4shell.com/en/7zip/asar/ or python script https://github.com/unitycoder/UnityHubPatcher )
  • rename old app.asar as app.asar.bak
  • Open app/ folder in VSCode/VSStudio (need to run as an Admin)
  • Open localProject.js
  • Add this line at top (near other definitions)
    const kPCustomNamePath = path.join(ProjectSettingsFolderPath, ‘ProjectName.txt’);
  • modify getProjectData(projectPath) method
  • Add these lines of code (inside green rectangles)
  • Open projectDataHelpers.js
  • Add these lines at the end
    exports.getCustomProjectName = getCustomProjectName;
    async function getCustomProjectName(customNamePath, defaultName) {
         try {
           const customName = await fileSystem_1.fs.readFile(customNamePath, ‘utf8’);
           return customName.trim();
         } catch (error) {
           return defaultName;
         }
    }
  • Make sure Hub process is closed completely (not minimized)
  • Save script changes
  • You can now add ProjectName.txt file inside Project settings to some of your projects to test it
  • Start hub again, if everything is correct, it should display custom title for that project

So then it uses same ProjectName.txt file like my custom launcher (which allows project rename with F2)
https://github.com/unitycoder/UnityLauncherPro

UPDATE 19.12.2023, you can add support for reading ProjectSettings Product Name field also, use this for the getCustomProjectName method:

exports.getCustomProjectName = getCustomProjectName;
async function getCustomProjectName(customNamePath, defaultName) {
     try {
        // if ProjectName.txt exists
       const customName = await fileSystem_1.fs.readFile(customNamePath, 'utf8');
       return customName.trim();
     } catch (error) {
     }
     try {
        // try to read ProjectSettings.asset next
        let settingsFilePath = customNamePath.replace("ProjectName.txt",""+"/ProjectSettings.asset");
        console.log(settingsFilePath);
        const settingsNameRaw = await fileSystem_1.fs.readFile(settingsFilePath, 'utf8');
        const settingsName = settingsNameRaw.match(/productName: (.*)/)[1];
        return settingsName.trim();
    } catch (error) {
        //console.log(error.Error);
    }
    return defaultName;
}

*08.12.2023 Generic disclaimer: For Education Purposes Only.


Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.