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
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
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, ...);
}
}
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.