Search Unity

  1. Tune in to get all the latest Unity news live from Berlin on June 19, 6pm CEST. Set up a YouTube reminder!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Manage Script Templates

Discussion in 'Unity Hub Preview' started by v01pe_, Feb 8, 2018.

  1. v01pe_


    Mar 25, 2015
    I like to replace the standard script templates with my own and also add a few custom ones. The script templates I'm talking about are those used when selecting e.g. Create -> C# Script from the context menu in the project window, or form the Assets menu.

    They are located inside the Unity install folder at on OS X and at Editor\Data\Resources\ScriptTemplates on Windows. Therein also lies the problem of modifying them… every time you install a new version of Unity, those are not present any more and have to be copied over to the new install folder, or are lost, if you install over the same folder.

    I wrote a script to place them where they belong for new installs, but through the Unity Hub would be a convenient way to manage these templates and make them available on all Unity versions installed.
  2. superpig


    Insert bacon, receive bugfix Unity Technologies

    Jan 16, 2011
    What if we made it that you could just put your custom templates in your project folder somewhere instead, so that you didn't need to modify the install?
    hadynlander and Iamsodarncool like this.
  3. v01pe_


    Mar 25, 2015
    Actually better would be if they could be put in a user folder like other Unity settings. At least the files that I'm using aren't really project specific. That's p.e. my `81-C# Script-NewBehaviourScript.cs.txt`:

    Code (CSharp):
    1. using UnityEngine;
    3. public class #SCRIPTNAME# : MonoBehaviour
    4. {
    5.     void Start()
    6.     {
    8.     }
    10.     void Update()
    11.     {
    13.     }
    14. }
    I thought about hooking them up with Unity Hub, because I often work on two different computers and the Hub would be a great way to not only keep them with different Unity versions, but also on different machines if they are synced.

    But I'd already very happy if I could override and add to the default ones by placing them somewhere in my Library folder.
    AlanMattano and Iamsodarncool like this.
  4. hadynlander


    Jan 24, 2014
    I realise I'm late to the party here, but it made more sense to reply to this comment than start a fresh thread.

    Anyway, I'd really like this! It'd be super useful to have template scripts with the correct namespaces baked in for different projects, both as a freelancer (jumping between many projects) and as a team contributor (ensuring consistency across the codebase). I could even see myself creating more specialised templates per project if I wasn't concerned about cluttering up the Create context menu in unrelated projects...

    So that's a resounding yes please from me, if it's not too late!
    Iamsodarncool likes this.
  5. AlanMattano


    Aug 22, 2013
    I'm afraid that if Unity for some technical reason changes the default templates, having my own template, I will not notice the difference and I will lose the upgrade.

    Is annoying searching inside C:\Program Files\Unity\Hub\Editor folder because folders of different Unity versions are not deleted. A fast link to the C# folder of that particular Vr can be a very good starting solution?

    Code (CSharp):
    1. using UnityEngine;
    3. /********************************************
    4. *
    5. *  2018
    6. *  #SCRIPTNAME#
    7. *  
    8. *      .
    9. *  
    10. *          .
    11. *
    12. * *****************************************/
    14. public class #SCRIPTNAME# : MonoBehaviour
    15. {
    16.     #region VARIABLES
    17.     [Space][Header("#SCRIPTNAME#")]
    18.     [Space(25)]
    19.     [Space]
    21.     // PUBLIC
    22.     public bool consoleDebug;
    24.     // PRIVATE
    25.     #endregion
    27.     void Start ()
    28.     {
    29.         #NOTRIM#
    30.     }
    32.     void Update ()
    33.     {
    34.         #NOTRIM#
    35.     }
    36. }
    38. /*
    39. using System.Collections;        // For sub rutine & making list
    40. using System.Collections.Generic;    // for making list
    41. using UnityEngine.UI;
    42. using UnityEngine.EventSystems;        // pass on what the button do when is click
    43.     [Range(0, 3.5f)]
    44.     [Tooltip("Info")]
    45.     [Space][Header("INPUTS")][Space]
    46.     [Space][Header("DRAG & DROP")][Space]
    47.     [Space][Header("OUTPUTS")][Space]
    48.     if (consoleDebug) Debug.Log("" + "\n");
    49.     void OnGUI(){GUILayout.TextArea("text " + VARIABLE.ToString() );}
    50.     GUIStyle guiStyle = new GUIStyle();
    51.     void OnGUI()
    52.     {
    53.         guiStyle.fontSize = 50;
    54.         guiStyle.normal.textColor = Color.white;
    55.         GUI.Label(new Rect(10, 10, 100, 20), "Notas: " + myVar1, guiStyle);
    56.         GUI.Label(new Rect(10, 65, 100, 20), "Infos: " + myVar2, guiStyle);
    57.     }
    58. /*------------------------------- FUNCTIONS -----------------------------*/
    Last edited: Jun 13, 2018
  6. v01pe_


    Mar 25, 2015
    I know this is already kind of an old thread, but here and then I think about it and the more I do so the more I like the idea of being able to put the templates into a folder somewhere inside the project. This way one could add even more specialised presets that only make sense for that project.

    Additionally it would still be nice to have a collection of template overrides that I want to include in every new project. This could be solved by a more general approach by defining custom project presets like "2D" and "3D" that already exist as dropdown in the new project view!
    hadynlander likes this.