Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 JoeW97 · Sep 16, 2014 at 11:07 AM · startup

Any way to load a script when Unity is opened?

I wondered if perhaps there was an undocumented file location where Unity could load a script from as it starts up. Or… is there any hook of any kind that would let you do something upon startup?

Thanks

Steve

Comment
Add comment · Show 2
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 GameVortex · Sep 16, 2014 at 11:36 AM 0
Share

http://docs.unity3d.com/$$anonymous$$anual/RunningEditorCodeOnLaunch.html

avatar image JoeW97 · Sep 17, 2014 at 07:43 AM 0
Share

Thanks, that's going to be useful for so many things. Presumably it still means opening an existing project to which a startup script has already been added. It would be great if it could be added to a 'New Project' template somehow, so it's guaranteed to be there. $$anonymous$$y final goal is to be able to start a new project and have it load a set of essential assets. At the moment I have a script that I add first, then run that.

2 Replies

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

Answer by HarshadK · Sep 17, 2014 at 07:55 AM

Yes. Check -executeMethod argument from the Command line arguments manual page which states the usage of it as:

Execute the static method as soon as Unity is started, the project is open and after the optional asset server update has been performed. This can be used to do continous integration, perform Unit Tests, make builds, prepare some data, etc. If you want to return an error from the commandline process you can either throw an exception which will cause Unity to exit with 1 or else call EditorApplication.Exit with a non-zero code. If you want to pass parameters you can add them to the command line and retrieve them inside the method using System.Environment.GetCommandLineArgs.

To use -executeMethod, you need to place the enclosing script in an Editor folder. The method to be executed must be defined as static.

Example code from that page itself:

 // C# example
 using UnityEditor;
 class MyEditorScript
 {
      static void PerformBuild ()
      {
          string[] scenes = { "Assets/MyScene.unity" };
          BuildPipeline.BuildPlayer(scenes, ...);
      }
 }

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 JoeW97 · Sep 17, 2014 at 08:06 AM 0
Share

Thanks, that very much answers my original question. It seems there is a chicken-and-egg situation though, where this can't work on a new project, only on an existing project to which you have added this script. (In which case, it was already possible to have one key press to invoke a startup script). Since reading yours and GameVortex's replies, I'm wondering if Unity exposes the details of a New Project template anywhere?

avatar image HarshadK · Sep 17, 2014 at 08:33 AM 0
Share

As long as I know, it does not. But one method is to create a package with your own project template and load that in your project at the startup using -importPackage command line argument.

avatar image
0

Answer by diliupg · Jul 14, 2020 at 04:22 AM

You can duplicate a projectTemplate which is in the Editor\Data\Resources\PackageManager folder and edit the Json file to load your own scripts on any project startup. I have edited the 3D template and the URP template to load my own scripts on startup and also edited the script template to carry my own message.

Comment
Add comment · 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

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

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

itween move to do not end(even it is) 0 Answers

Fps Aiming Script help 2 Answers

support not detected collision and Leasehold 0 Answers

Can I use DataTable in unity and how? 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