x


Running a script when Unity starts.

I'd like to run and editor script as soon as Unity launches. The closest I've been able to come is by using a CustomEditor on type Object, which launches as soon as something is selected.

Is it possible to run an editor script function when the Unity editor launches?

more ▼

asked Sep 09 '10 at 07:30 PM

HeywoodFloyd gravatar image

HeywoodFloyd
288 5 7 18

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first
more ▼

answered Feb 25 '11 at 04:33 PM

oxymoron gravatar image

oxymoron
51 2 2 7

(comments are locked)
10|3000 characters needed characters left

I have taken the excellent code from the answer pointed to by vitamine and added it to the Community Wiki at http://www.unifycommunity.com/wiki/index.php?title=Autorun .

Cheers!

more ▼

answered Oct 01 '11 at 06:14 PM

MattMaker gravatar image

MattMaker
71 1 3

(comments are locked)
10|3000 characters needed characters left

You could try a couple of different methods with OnEnable() (for example, on a class derived from "Editor", or on a custom editor window, or something like that). The only other way I could think of is to have a script with Start() or Awake() and have it set to ExecuteInEditMode, though I'm not sure if that would work.

more ▼

answered Sep 09 '10 at 07:55 PM

qJake gravatar image

qJake
11.6k 43 78 161

Thanks. I'll have to try the Editor window.

Currently, I'm using a class derived from Editor tied to UnityEngine.Object via the CustomEditor command. That runs the OnEnable method as soon as anything in the project or hierarchy is selected (which may be good enough), but not when Unity starts up.

Sep 10 '10 at 04:18 PM HeywoodFloyd

Did you also try the constructor on the Editor-derived class? That might work, too :P

Sep 10 '10 at 06:50 PM qJake

I did try the Editor-derived scripts. Their OnEnable methods aren't run until an object for which they're attached via the CustomEditor command is selected.

I also tried putting in an internal class whose constructor did what I want, and making a static instance of it. Again, the inner class's constructor wasn't run until an item was selected.

Sep 15 '10 at 06:26 PM HeywoodFloyd
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5058
x1664
x347
x64
x51

asked: Sep 09 '10 at 07:30 PM

Seen: 3558 times

Last Updated: Oct 01 '11 at 06:14 PM