Unity Script Templates - Changing default script content
// Update is called once per frame
I freaking get it, stop showing me!
Don’t put up with the standard Unity templates, make your own! Change the default content in created assets.
Go sub to Jason Storey: / jasonstorey
❤️ Become a Tarobro on Patreon: / tarodev
=========
🔔 SUBSCRIBE: bit.ly/3eqG1Z6
🗨️ DISCORD: / discord
✅ MORE TUTORIALS: / tarodev
Пікірлер: 98
Better than a fixed namespace is, to add: #ROOTNAMESPACEBEGIN# and #ROOTNAMESPACEEND# Then you can set the Namespace inside your Project (Project Settings/Editor - C# Project Generation - Root namespace)
@Tarodev
2 жыл бұрын
That is indeed better. Good tip!
@nguyeninhtai5244
2 жыл бұрын
Can you show the example? I can't get it :((
If you like short ones, I've got two for you. 1 - You can save the files you make with the font asset creator for Text Mesh Pro, so you don't have to remake them every time you start a new project. 2 - If you're like me, when developing a new system, you might make a bunch of new scripts at once. Like say while making an inventory system. You'll need a base item - derivative item types - an inventory - etc. Making them one at a time is slow, as each will force unity to do a reload. Just open up a script, and deliberately create an error. You won't have to go through a reload each time you make a new script. Saves a lot of time.
I've been needing this for the last 6 years
Jason also helped me out on some stuff, he's great :) Thanks for the tip bro!
Always learning something new. Your channel is the next best thing since sliced bread. 🍺
Simple and straight to the point. Thank you!
@diligencehumility6971
2 жыл бұрын
Yeah this channel is quite good
@Tarodev
2 жыл бұрын
Thanks boys
Almost 20K, Let's gooo!! Also Code Monkey mentioned your channel in one of his live streams!!
@Tarodev
2 жыл бұрын
omg WHAT? What did he say??
@kingbling7571
2 жыл бұрын
@@Tarodev Someone asked him which Great Unity YT Channels he follows and he starting listing some and you were one of them as well :P He also mentioned he recently found it and that it had some amazing videos that one should watch if they have time. Ik this is great n all, but I know you can reach over 100k in coming time! Let's goooOoOoOo
@Tarodev
2 жыл бұрын
@@kingbling7571 Mind blown. I've been watching CM for so long and it's insane to think he knows I exist, lol!
@kingbling7571
2 жыл бұрын
@@Tarodev yup, must be an amazing feeling. Well u do deserve some recognition after all. Also don't forget that I exist when you grow large, jk lol
Super dope! Also really cool that you know Jason Storey, he's really cool imo.
@Tarodev
2 жыл бұрын
He's alright I suppose
Thank you for the amazing tutorials
@Tarodev
2 жыл бұрын
You're like text mesh pro, but backwards!
Such a small thing but making life so much better :D. Love it!
Another benefit with this would be adding a symlink if you have multiple versions, that way you would only have to change one file/folder once to have it applied to all versions of Unity you have downloaded. Thank you for the quick tip Tarodev!
Yeah I found out about this some years ago. What is annoying is, you have to do this ever time to update unity or download a new version. The templates should be shared so you can use the same templates
@Tarodev
2 жыл бұрын
Absolutely agree. I suppose it's not because they may change bits and pieces from the templates.
@Vastlee
2 жыл бұрын
Was going to reply the same thing. There's no reason for it either. Unity could easily store it in the user profile of the machine. Such a simple fix.
Cheers, no more correcting new scripts before I can start working with them!
pretty cool, tho I usually add a blank class from rider since it has a better project view and shows which assembly is the parent
Good tip, but you can make Visual Studio templates too for Add New Item menu ... super handy thing to know. I create all my new .cs files in Visual Studio anyways.
That was really cool✌️
You can also do this without changing the editor default templates by putting it on a special folder inside yout assets folder, this way everyone that works on the project will have it too
It is very cool, but due to being software in constant evolution you are always downloading the next lts versions, and you would have to do it in all of them. Apart from this, one more useful tip. thanks
Or you can put the "ScriptTemplates" folder inside your "Assets" directory, and changes the scripts as your liking, then just restart the editor. And you are done. It does not matter you update unity or move your code to a different system it should just work.
@IlPandax
2 жыл бұрын
Yes but only for a specific project, right?
@nikobellic7455
2 жыл бұрын
Yes, its not for all project or system wide, so it also may not be ideal in all cases, but its still another way to do it. Pick whichever method is suitable.
@KeyboardKrieger
2 жыл бұрын
Even though I use the same templates in all projects, this solution seems to be less hacky and more straight forward.
@joaolira7
Жыл бұрын
Makes more sense doing your way. Every project can have a different namespace, for example.
@joaolira7
Жыл бұрын
@Niko Bellic Does the script must have a specific name?
AMAZING!
Great video! I might add more using statements, so I can delete the ones I don't need. CTRL+X deletes a Line (uses clipboard) Shift+Delete does the same (uses clipboard).
@buzatusebastian2735
11 ай бұрын
and shift delete also deletes a line without storing it in the clipboard
@Rovsau
11 ай бұрын
@@buzatusebastian2735 Thanks! I'll update that in my post.
@buzatusebastian2735
11 ай бұрын
@@Rovsau nvm shift del still stores the line in the clipboard wow. Just found that out srry
@Rovsau
11 ай бұрын
@@buzatusebastian2735 ah lol, I missed that myself xD
What is the font type you use for the notes in the video? Nice tip btw, thx!
Excellent vid, those comments are so annoying haha. I may edit it to just get rid of the start and update function straight away too
Hey Tarodev, Would you be able to make a tutorial about a combat or text log? Like in those CRPGS (Fallout 2, Baldurs Gate) where you have a small window to the side with a bunch of scrolling text telling you what you hit and for how much damage, or telling you information about an object you clicked on. Thanks for the videos!
@Tarodev
2 жыл бұрын
Great suggestion!
Thank you -- I've been wondering how to change this for a long time. I'm on Linux, so the path was a little different.
That's great! I didn't know that. ;)
Super cool! Regarding namespaces, I think I understand the concept but I never find a reason to actually use them, it feels like it adds an unnecessary extra layer of complexity to your project, and if you are going small indie projects it seems redundant… Would love to see a a video about namespaces and their use. Other than that I am really enjoying your content man, thanks a lot! Everything is super helpful!
@mementomori7160
2 жыл бұрын
In short, by using namespaces you somewhat enforce to write cleaner less tangled code. I thought the exact same thing like you some time ago, but now I'm slowly changing it. There is a channel infallible code or something like this, they covered it nicely
@kingbling7571
2 жыл бұрын
It acts as a barrier which is always nice when you need to clearly define a line between two different modules n such
@modiddymo
2 жыл бұрын
Also in larger projects it shows you which modules a given class depends on by giving you a list of using statements at the top of your file.
@jeffmccloud905
2 жыл бұрын
Think of them like folders/sub-folders of your file system. They are for organization and to prevent naming collisions (imagine two classes named Button or Weapon). They become particularly important on large projects or when you make/reference DLLs
@midniteoilsoftware
2 жыл бұрын
kzread.infosearch?query=namespaces
Can you do one of these on namespaces please? I kindda understand them but also i have no real idea what/why/when/where/how. Also, thank you.
Nice one, I will do that at first on Monday xD
@KeyboardKrieger
2 жыл бұрын
Maybe it was today and not the following monday, but hey at least it's a monday and I finally used this tip^^
@SkorpionYassine
Жыл бұрын
@@KeyboardKrieger lmaoo
Great 💯 Thanks.
You can also set the Namepsace via the Edit > Project Settings> Editor > ROOT NAMESPACE
@Tarodev
2 жыл бұрын
Sure do wish I knew this before I did this video :)
@jamesfoward7761
2 жыл бұрын
@@Tarodev ^_^ the video is great, I had no idea you could remove those pesky empty Monobehaviors calls/libraries
@kingbling7571
2 жыл бұрын
@@jamesfoward7761 does it include the namespace in every new Script u create?
@jamesfoward7761
2 жыл бұрын
@@kingbling7571 Yes sir
@nguyeninhtai5244
2 жыл бұрын
I can't generate namespace by your way in UnityEdior2019
For me it was empty folders in c:\Program Files\Unity, but found it in my home folder c:\Users\USERNAME\Unity\VERSION\Editor\Data\Resources\ScriptTemplates\
thank you for the tip. Now my Unity is creating a new testscript instead and i dont know how to undo the damage.
You can also have multiple templates of that and choose which you want.
@guyginat
2 жыл бұрын
How do you do that?
@Tarodev
2 жыл бұрын
@@guyginat I'm also interested in how this is done
@Shonia
2 жыл бұрын
@@Tarodev Idk if I can post link here so... Search youtuber "Coding With Unity" and the name of video is : Unity3D - Create, Edit and Rearrange Script Templates
@Shonia
2 жыл бұрын
@@Tarodev Hope it helps!
This is great for when creating new scripts. But is there a template I can change so it doesn't put the annoying private keyword when adding new methods (e.g. Awake, OnEnable, etc.)?
Haha thank you. Cool beansss
Why did they choose to store the templates in the version folder? This means your templates are lost when you update Unity, which is pretty much every time you start a new project. Why couldn't they store the templates in the AppData folder, along with all the other presets (such as keybinds and layouts)?
So i'm saving it and trying to replace the original but it says access to the path is denied. Care to help?
how can i learn a littble bit more about script template ?
It's really useful. The only annoying thing is that you need to repeat it every time you download a new Unity Version
@KeyboardKrieger
2 жыл бұрын
If you stay to LTS versions it's only one or two copy & paste a year.
@SolonisRex
Жыл бұрын
Put them in the directory "Assets/ScriptTemplates". Unity looks for this folder and you can do it on a per project basis. This really is the best way to do it.
Am I really first 😅, and great video, now I will get rid of those start and update methods
Any clue why Time.deltaTime would not work in my script? It says 'float' does not contain a definition for 'deltaTime' and no accessible extension method 'deltaTime' accepting a first argument type 'float' could be found. Restarted VS and unity, regenerated project files and tried the unity debugger without success. I am stumped... It still works in other scripts. fixedDeltaTime also would produce a similar error if I try to implement it under the fixedUpdate.
@MaZyYTube
2 жыл бұрын
You are in wrong place
@TriCombStudio
2 жыл бұрын
@@MaZyYTube this comment especially proves that with how abundantly helpful it is. My issue was resolved thanks to posting in comments sections though... so high five to people who comment regardless of how ignorant their opinions are for getting the ball rolling!
@MaZyYTube
2 жыл бұрын
@@TriCombStudio its good for you but imagine this video would have full of off-topic comments like this help request / questions it wouldn't make fun to read anymore.. and some bigger ytber already have this and needed to start deleting comments. Do you want it same here? I mean I would understand if this were related to the video. 2. It is harder to help in yt comment section. Better to use unity forum, reddit or discord. It is easier to share code and to analyse it.
@TriCombStudio
2 жыл бұрын
@@MaZyYTube This reply was far more useful than your first comment, I probably could have actually used this advice
I've been growing quite sick of those default comments.
@Tarodev
2 жыл бұрын
Now you'll be free of them!
it's slightly annoying this has to be done for every (new) install of unity. An interesting addition would be to show how to add custom menu entries to create c# scripts using specific templates
@Tarodev
2 жыл бұрын
You mean like what should already be built in to Unity? Man, I've been wanting this for years!
@fleity
2 жыл бұрын
@@Tarodev Yes absolutely! :D It actually doesn't sound that complicated. I feel like I could build that... I might just do that
@fleity
2 жыл бұрын
@@Tarodev OH WOW! I didn't knew until a few minutes ago but this has been built into Unity all along already. Just duplicate the script template and give it a new valid name: {SortingIndex}-{MenuItemName}-{FileName}.txt restart unity if it's already open
Now if only there was a way to not have to repeat this operation with each new version of Unity.
@MaZyYTube
2 жыл бұрын
Yes annoying but you could write a batch or shell file or even with c# to make little automization