Skip to main content
Search our knowledge base

How to customize Unity script templates




    good logic of using templates efficiently unity seems to be self sufficient framework. it could be more useful if theoretical details were provided like utility scope and areas where it is used in the animation graphics and gaming industry[ the sub sectors]

      Nikhil Pande

            Technical Team Lead : Incedo; Chennai, India

  • tomas almera
  • Tijmen van den Heuvel

    When doing this in version 5.5 i saw something new, in every method body there was the following text: #NOTRIM#


    What does this mean?

  • Iain Gilfeather

    Re. #NOTRIM#, good question.

    The short answer is you can either leave them in your templates or remove them. It makes no difference because they are stripped from any new script asset generated from that template.

    To explain why they are there, in Unity 5.5, tabs were added to some empty lines in the templates for better indentation. The #NOTRIM# text is a special marker used by the template file system to mark lines that end in whitespace, like tabs. They prevent that whitespace from being stripped by our source code tools. The Unity Editor then strips all the markers when the template is used.

  • Laurie Harper

    Nice to know. Are there other placeholders available besides #SCRIPTNAME# and #NOTRIM#?

  • Gregg Tavares

    I sure would be nice if Unity would instead use some user data folder like C:\Users\Person\AppData\Unity\templates or ~/Users/Person/Library/Applicaftion Data/Unity/Templates

    As it is every time a new version of unity is installed I have to manually fix the templates

  • Thamas Arron Bell

    I Cover this a little further on my website, but the link at the bottom will bring you back here.. aka never ending loop... But I explain how to modify these and not lose them on an install. Best way i have found in short, is to change the number in the beginning or change the name just slightly so Unity doesn't overwrite your template on an install.

    If the file on the install has the same name as the one in the file it is suppose to go in, it will automatically overwrite without even telling you, or asking you. So to prevent, never use original script names. and since we can only use 1 C#  template at a time, the lowest number before your script suffix and name will be the one to load into Unity.

    EG on name Layout:

    # 81 or lower + "-C# Script-" + "ScriptName.cs".txt


    Hope that solves your issues @Gregg Tavares

  • Liam Rüdel

    While having local templates is great its not very practical when working in a team, but thanks to this tweet: I've come across the solution! You can add project ScriptTemplates. Simply add your templates to Assets/ScriptTemplates and restart the editor.

    You can now create and share( via source control ) script templates on a project level!

  • Thamas Arron Bell
    @Liam Rüdel Great find, should have known better thinkin of Resources and Editor as oither's that work similarly ahah that's awesome though!
  • Steven Delrue

    If you use the Uniyt Hub, the location of the files is at C:\Program Files\Unity\Hub\Editor\<UNITY_VERSION>\Editor\Data\Resources\ScriptTemplates

  • super helpful, thanks

  • Stacy Smith

    I am not sure if this has changed, but I am using version 2019.3.15f1 on Windows 10, thus my ScriptTemplates folder is at "C:\Program Files\Unity\Hub\Editor\2019.3.15f1\Editor\Data\Resources\ScriptTemplates", I have added my custom script template and have named it "82-C# Script-NewKitBehaviourScript.cs.txt", however, it does not show in the Add Component list.

    The contents of the cs template I have created match those in the "81-C# Script-NewBehaviourScript.cs.txt". As a basic test of this issue, I changed the name of that file to "81-C# Script-NewBehaviourScriptA.cs.txt", which I imagine should change the name in the editor, however, it does not - it appears to have no effect.

    I am not sure what I am not doing correctly.

  • Stacy Smith

    Well, it looks like changing the name of the original NewBehaviourScript did have an affect on Unity. I get this now when I try to create a new behaviour script:

    FileNotFoundException: Could not find file "C:\Program Files\Unity\Hub\Editor\2019.3.15f1\Editor\Data\Resources\ScriptTemplates\81-C# Script-NewBehaviourScript.cs.txt"

    So, this must mean that path is being stored somewhere. I'd need to change that too - anybody got a clue where it might me?


  • Laurie Harper

    Make sure to restart the Unity Editor after making any script template changes. I prefer to keep my script templates in my project, but whichever location you use, you still have to restart the editor after changes for them to be seen.

  • Stacy Smith

    Thanks Laurie, however, I did reset. I really would prefer to keep the templates in my project like you have suggested; how do you handle that, and how do you do it? 

  • Laurie Harper

    @Stacy see this earlier comment.

  • 0

Please sign in to leave a comment.