command args unity

Hi all! I’m trying to do the following - I programmatically copy the script to an empty project, this script is needed in order to create the project programmatically. Next, I launch the application with launch arguments. What I expect is that the project has opened, the script that I ogrammatically added to tprhe project before launch has the InitializeOnLoadAttribute attribute, that is, when the project is opened, “running editor code on launch.” But in the end, the editor writes to me after opening that Error building Player: Unity has not finished loading yet.
img-1


img - 2

In the first screenshot, the program copies the required dll into an empty project. This dll must be executed when the project is opened. In the second screenshot, the dll code itself

AFAIK no code will be executed by Unity until Unity is able to compile ALL the code in all assemblies, which obviously requires the project to exist and be error-free.

What exactly is your intended goal here?

If you want to build the player, you will have to use “-executeMethod” command line argument when starting the editor as opposed to using [InitializeOnLoad]. Pretty sure you are not allowed to build the player from within [InitializeOnLoad] methods.

My goal is to create software that will compile my projects. That is, I have projects, but before assembling them, I need to perform a number of actions that I now do manually. It is necessary that the software does it for me and builds the project

I already did this, and the project is going to work, but in order to work this way, you must first open the project and create a script there that you can call with an argument before launching, and I want to write software that will add this script for me, and after that my program will already launch unity with executeMethod argument

Just pre-write the script and File.Copy it into the Assets folder of the project before running Unity.exe.

I did this - I wrote a script that is called with an argument before starting unity, alas, this does not work. That is what it looks like. I copy the script to an empty project in the Editor folder. And after -executeMethod <ClassName.MethodName> or -executeMethod It doesn’t work

1* script in which it is written to build the player
2* Where to copy


After clicking on compile, my program should copy the required script to an empty project along the path (2*)? and then run unity with the execute argument

8177234--1064717--upload_2022-6-3_0-43-39.png

What does “it does not work” mean? Does the editor error out? Does it say it cannot find the method? What’s the full path that you copy the script to and what are the exact arguments you launch the editor with?

You need to copy the script into the “Assets” folder, like “C:\Users\UserName\Documents\MyProject\Assets\Editor”. Unity doesn’t compile scripts outside of Assets and Packages folders.

It works, apparently I forgot to call the script in the arguments earlier. Another question, can I somehow display the build process with the -nographics argument?

You can use the -log argument to route the log output to a file, then have another process keep reading data from that file as Unity writes into it.

1 Like

That’s a good idea, thanks for the tip! At the moment I have no questions, but I will definitely contact you again, because in the future I want to know if I can also completely programmatically configure the remote config and build after the project

Why doesn’t it work? Displays only the last line of the previous file

8179433--1065179--upload_2022-6-3_22-27-59.png

Try something like this: Continuously read file with C# - Stack Overflow

1 Like

Thanks, it helped! There was a question, if I want to split and output the stages of the assembly… I can read a string from the stream and compare with something. As I understand it, for assemblies of different platforms - different build steps?

In other words, how do I make a progress bar?