Is there any way to create a script from an editor window?

Yes indeed! I do so for my code generation step in my Datasacks repo. As long as you call refresh afterwards it will recompile just fine.

Code here: https://github.com/kurtdekker/datasacks/blob/master/datasacks/Assets/Datasack/Core/DatasackInspector.cs

Function GenerateCode() is where it starts:

  • line 255 is where it fwrites the source code file
  • line 298 saves assets (but I don’t think you need that)
  • and finally line 301 does the refresh, which triggers the recompile.

Just make sure you don’t write code with an error, because then you won’t be able to recompile your code-generating code and you get stuck in this very annoying loop. :slight_smile:

Also, I offer you my standard source control plug, just in case you’re not already source controlling:

Please consider using proper industrial-grade source control in order to guard and protect your hard-earned work.

Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

As far as configuring Unity to play nice with git, keep this in mind:

https://discussions.unity.com/t/736093/3

Here’s how I use git in one of my games, Jetpack Kurt:

https://discussions.unity.com/t/807568/3

Using fine-grained source control as you work to refine your engineering:

https://discussions.unity.com/t/826718/2

Share/Sharing source code between projects:

https://discussions.unity.com/t/719810/2

Setting up the right .gitignore file:

https://discussions.unity.com/t/834885/5

Generally setting Unity up (includes above .gitignore concepts):

https://thoughtbot.com/blog/how-to-git-with-unity

It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place.