Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

So I tried to change my Script template today.....

Discussion in 'Scripting' started by Ne0mega, Apr 6, 2021.

  1. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    465
    FUTURE READERS: Read Second post if you want to know the easy way to do this.


    First it took me 10 minutes to figure out how to change "administrator permission" on my Windows 10 machine for this ONE little text file, so I could save it.

    This little text file is called "81-C# Script-NewBehaviorScript.cs.txt"

    I changed it to this:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class #SCRIPTNAME# : MonoBehaviour
    5. {
    6.    [TextArea(0,0)]
    7.    public string empty_Script;
    8. }
    9.  
    A little relaxed now, it was worth reading all those articles about how to change administrator permission on a file, constantly trying things, saving, being told I don't have permission etc, (this was the trick for, future frustrated Unity devs using Windows10 https://thegeekpage.com/how-to-fix-you-dont-have-permission-to-open-this-file-error-in-windows-10/)
    a) Right-click on the file which you’re unable to access and select Properties.

    b) Click on ‘Security’ tab and under ‘Group or user names’ click on ‘Edit’.

    c) Click on ‘Add’ and type ‘everyone’.

    d) Click on ‘Check names’ and then click ‘OK’.

    e) Select ‘everyone’ and under ‘Allow’ select ‘Full control’ and click on ‘Apply’ and Click ‘Ok’.

    Anyways, create test script... still using annoying old template that takes an extra 5 seconds to clear out with every start, for no reason.

    Alright I think, need to refresh visual studio, and I'll restart Unity too...

    Restart them....
    ....Nope. new script still has the old stupid commented Update and Start template.

    Guess it's time to delete my library file, and rebuild? No Thanks.

    Oh, and I bet the next time I install a new Unity version, I get to do all this all over again, or I can just be annoyed by deleting the worthless noob drivel (that has never helped a single Unity or scripting noob) they fill the starting template with, on every, single, new... script... I create....
     
    Last edited: Apr 6, 2021
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,315
    You can actually do this in your project folder itself now (which I didn't realize until I googled just now, so thanks for prompting me to learn this!). Not sure when they added this feature but you can:
    1) Create Assets/ScriptTemplates/TemplateName.cs.txt
    2) Put your template in there, with the #SCRIPTNAME# placeholder
    3) Restart Unity

    And boom, there it is!

    By the way, if you're going to go to the trouble of making your own script template, please put your class in your own namespace.... it's a good habit to be in.

    upload_2021-4-6_17-43-48.png
     
    Ne0mega likes this.
  3. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    465
    Silly me, trying to use the official unity support page:

    https://support.unity.com/hc/en-us/articles/210223733-How-to-customize-Unity-script-templates
     
unityunity