Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by HeywoodFloyd · Sep 09, 2010 at 07:30 PM · editoreditor-scriptingstartuplaunch

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by oxymoron · Feb 25, 2011 at 04:33 PM

This could help

edit: new link: http://answers.unity3d.com/questions/45186/can-i-auto-run-a-script-when-editor-launches-or-a.html

 using UnityEngine;
 using UnityEditor;
  
 [InitializeOnLoad]
 public class Autorun
 {
     static Autorun()
     {
         Debug.Log("Autorun!");
     }
 }

or if u want for the scene to be loaded, hook to the editor update callback

 using UnityEngine;
 using UnityEditor;
  
 [InitializeOnLoad]
 public class Autorun
 {
     static Autorun()
     {
         EditorApplication.update += RunOnce;
     }
  
     static void RunOnce()
     {
         Debug.Log("RunOnce!");
         EditorApplication.update -= RunOnce;
     }
 }


Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ruudlenders · Jul 04, 2014 at 02:12 PM 0
Share

The url is dead now.

avatar image oxymoron · Oct 15, 2014 at 10:08 PM 0
Share

fixed url, copy pasted answer to be sure

avatar image
0

Answer by qJake · Sep 09, 2010 at 07:55 PM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HeywoodFloyd · Sep 10, 2010 at 04:18 PM 0
Share

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.

avatar image qJake · Sep 10, 2010 at 06:50 PM 0
Share

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

avatar image HeywoodFloyd · Sep 15, 2010 at 06:26 PM 0
Share

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.

avatar image
0

Answer by MattMaker · Oct 01, 2011 at 06:14 PM

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!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image acakebread · Oct 12, 2020 at 02:07 PM 0
Share

this is some sort of scam

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How can I preserve static object/data between editor and play? 2 Answers

HideFlags on children of visible objects. 3 Answers

Unity Editor Scripts: GameObject Added / Removed Event? 1 Answer

How to record the entire game and user behaviour for a research project? 1 Answer

problem with the digits of my timer 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges