Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Feedback Unity Hub - Script Templates feature request

Discussion in 'Unity Hub' started by PaintNPixels, Aug 15, 2019.

  1. PaintNPixels

    PaintNPixels

    Joined:
    Apr 15, 2015
    Posts:
    5
    Just as you can define which Unity version and Platform to open a Project in through Unity Hub, I'd love to see the ability to define Script Templates on a per project basis tied to your account.

    One of the frustrating things about script templates is that they are overwritten each time you update Unity and most importantly, lack the ability to be customized per project.

    Desires
    • Define a custom script template set per project
    • Save these variations to the cloud storage attached to my account to be accessible on multiple machines
    • Have access to custom tokens such as $PROJECT_NAME or $CURRENT_HUB_USER which can be used in aid in script header commenting
     
    unnanego likes this.
  2. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,270
    I don't think the Hub is a place for this; this should be implemented in the editors.

    You can customise your templates in each project; just drop your new templates into Assets/ScriptTemplates and restart the project.
     
  3. AbrahamDUnity

    AbrahamDUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    431
    Hi,

    We've had feature requests related to Script Templates in the past. I'm not sure we can prioritize these compared to other features more in demand right now. I'll relay the suggestion to the team but I can't promise anything.

    Cheers,
     
    unnanego likes this.
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,651
    You can put script templates directly in your project. Details.

    Don't know why Unity doesn't document it.
     
    AbrahamDUnity likes this.
  5. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,270
    I cannot get this to work in 2019.2.0f1, 2019.2.1f1 and 2019.3.0a12.
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,651
    Works for me in 2019.2.0f1.

    You copy the entire ScriptTemplates folder from Unity/Hub/Editor/2019.2.0f1/Editor/Data/Resources/ScriptTemplates into Assets. Then you edit the script templates you care about, before restarting the editor.

    The templates are loaded on startup, so after any edit you have to restart the editor. Which isn't ideal, but that's how script templates are loaded from the install, so it's at least not worse than that.
     
  7. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,270
    That's what I did, except that I kept only the template I wanted to edit into the ScriptTemplates folder I copied into Assets.

    It's not a problem anyway; I'm used to override the default template with the new one each time I install a new version of Unity. :)
     
  8. joaoborks

    joaoborks

    Joined:
    Jul 7, 2015
    Posts:
    21
    @PaintNPixels I have also requested this feature here and received the same feedback. Since then, I've created a simple tool to do what I wanted to suit my needs. I know that we can create templates for projects individually, but I use my templates on all of my local projects. Just figured it would be better, and it's working just fine so far.
     
    Last edited: Dec 12, 2020
    unnanego likes this.
  9. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    170
    Came here to support the cause. I'd say Hub should have this implemented.
     
    joaoborks likes this.
  10. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,270
    I don't see how script templates can be related to the Hub, only the editors use them. Do you have something precise to propose? What do you imagine it would look like?
     
  11. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    170
    Well, hub can have sets of templates like "FPS", "Shooter", etc. and they can be applied to the editor from the hub, since it's just files. This way you won't have to change much functionality and will be able to replace the stupid default templates with a click of a button - there are a lot of updates and each one requires you to replace the templates. Not much of a struggle, but still)
     
    joaoborks likes this.
  12. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,116
    I believe script templates belong to each project because different projects require different templates. However, the ScriptTemplates folder within Assets only applies to scripts created via the assets create menu, but not when using AddComponent in the inspector, so this only a 50% solution.

    You then have the issue, that a project script template is ok for starters, but each team member might want to add, e.g. their author name to a script, so that would be something that needs to be handled per user. I'd love for Unity to provide a way to customize the templates in such a way that it supports user macros. So basically, allow users to add ScriptTemplates in their assets folder, but input macro variables such as %AUTHOR% and then let users define these variables in their user preferences. This would be something I could implement myself if I could override the create script and AddComponent commands. So maybe, it would be better to just add extension points to these instead.

    However, then there's still a third issue: when creating a script via your IDE, it handled templates in its own way and doesn't communicate with Unity at all. I guess the only solution would be to add specific Unity support via plugins to e.g. Rider and Visual Studio in that case.

    As an addition to these basics, I would agree that the Unity Hub could serve as a central point to manage user preferences that are shared across all projects. However, as with all settings, I believe this requires a robust override system. If at all, it would need to allow global templates and variables defined via the HUB, but let each project override these with project templates and project user variables.

    Once all of that works neatly I could also imagine cloud storage on top of everything, but now things have a really big scope and I do agree that Unity's time might be better focused on other aspects, so I'd be fine with two simple callbacks for creating scripts to add my own template into. :D
     
    unnanego and joaoborks like this.
  13. TripTron

    TripTron

    Joined:
    Dec 19, 2020
    Posts:
    2
    Where even is the editor?...
     
  14. TripTron

    TripTron

    Joined:
    Dec 19, 2020
    Posts:
    2
    I cannot see a editor download place.
     
unityunity