Search Unity

Update: The Create Script Dialog is now on the Asset Store

As our NinjaCamp project Bas and I decided on a cause a bit humbler than many of the other projects going on here: We just want to improve the workflow of creating a new script in Unity.

The current way to make a new behaviour for a GameObject in Unity is like this:

  • Create the script in the desired folder.
  • Rename the script.
  • If it’s a C# script, rename the class to match the file name.
  • Drag the script onto the GameObject.

With the solution we’re working on, you can instead just choose “New Script” from the Components menu, and you’ll get this:


New Script Dialog 

This is a work in progress, but much of the base functionality is already there. While the window is open (which will float on top) you can optionally click any GameObject or Prefab to make the script be attached to that, and you can click any folder in the Project view to save the script in that folder. You can also pick which of the built-in callback functions you want included from the beginning (we only have four right now but we’ll add the others as well).

When you click “Create and Attach” the script will be created with the right file name and class name, compiled, and then added to your selected GameObject or Prefab if you chose one.

We’re also adding this partially related button:


Add Component Button 
The idea here is to just make it more obvious and simpler how to add a component to a GameObject – no need to reach for that menu anymore. And no, the button is not part of the AudioSource component, it’s below it and is still missing some style work and a separator line above it. It’s a work in progress!

We’re still missing more work on the script template building options, but I can already see that this thing will save me time in the future, if nothing else. ;)

29 replies on “NinjaCamp III: New Script Dialog”

It would be nice to be able to select bracketing style (K&R / Allman) – I always change the brackets, first thing I do on every new class :-P

Some way of setting up a standard code template would be nice too – something that gets stored with the project so that it doesn’t get rewritten with each new Unity version, and you could use a different template with each new project if you liked.

“how about a search widget on top of that menu…type box, press enter, wam bam here comes a box collider”

That’s a great idea. I have loads of scripts sorted in folder etc which I know where they are and what they’re called. It’s slow to mess about popping open folders etc

I’ve been manually editing the NewBehaviour scripts in the Unity Application package (to add #pragma strict by default and match my coding conventions). But the problem is that after an upgrade they revert back to the Unity default version. I’d love to be able to set default templates that would not get lost between updates.

Being able to select which functions to add will save me a lot of time hunting through the docs for which function definitions in MonoBehaviour have special meanings for Unity (no more asking myself, is it OnCollisionExit or OnCollisionLeave every couple of months). Great workflow improvement!

if you can not work on templates so just let us choose an script to add it’s content to the new script. let users put all script templates in a folder in unity’s installation directory and choose from them in new script dialog.
change the formatting of { } please. it’s something really uncommon and unwanted!
i know that others said these 2 before but just want to tell it another time!

Cool! Anything to make our lives easier is wellcome.
That is a great idea and very intuitive way to create scripts form scratch.

¡Guys, think in more improvements like this one, please!(and get them to life)

There could be a button to choose an existing script. This scripts includes (UnityEditor, Generics, …) and standard functions (Awake, Start, …) would then be taken and put into the new script. This would be a really nice way to have absolutely free templates – everyone could use it the way he wants. Like me – there would a handful of “template” scripts in the Inspector, and I could choose between them. Would in a lot of cases be much faster than copying the script, renaming, assigning to new object (together with your Create-and-Attach functionality). Cool idea!

You should add options for the lifespan of the object in the awake (dont destroy on load)

@require component

And the menu label

with those options it makes it more streamlined to not forget them ;)

This is promissing, how about a search widget on top of that menu,
Workflow would then be:
click Add Component
type box
press enter
wam bam here comes a box collider

That’s a good idea FierceForm… I wouldn’t use that feature personally, but I know that some people just like that formatting better.

Great job, Unity team!

Please let us select if we want to put the brackets on the next line. I hate having to always format the script when I open it.

Neat, flow is everything in Unity. The button in the inspector is much better.
How about a tick box to place the { } on the next line? Braces on the end of the previous line confuse my students and drive me insane :)

Excellent stuff. Seeing this makes me believe that the “eat your own dog food” does not get forgotten. Great, more of this kind of workflow enhancements!


It’s exactly this kind of small keen polish which I love and helps so much more than big features, or shiny things.

Great! The button should go in even if the script stuff can’t make it. But it all looks great!!

Please add Start() and Awake() function template checkboxes, too.

Neat! That makes a very frequently used part of the workflow way more streamlined and self-explanatory. It also seems like something that can be designed, created and finished in a week, and deployed in a future release without much trouble. :)

Comments are closed.