Search Unity

[RELEASED] UCmd: Supercharge Unity's command line runner

Discussion in 'Assets and Asset Store' started by liortal, Sep 28, 2018.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    upload_2018-9-28_15-57-42.png
    UCmd | Run any method from the command line!
    Download on the Asset Store

    Features
    When running Unity from the command line using the -executeMethod parameter, only static parameterless methods are supported.

    With UCmd, you can execute any static method with its arguments, directly from the command line.

    Example Usage
    Consider the following C# method for building asset bundles.
    Since parameters are not supported when calling this code from the command line, we need to write some boilerplate code to extract the parameters we need:
    Code (CSharp):
    1. public static class Builder
    2. {
    3.     // parameters are not supported  :(
    4.     public static void BuildAssetBundle()
    5.     {
    6.         var args = Environment.GetCommandLineArgs();
    7.         var assetBundleName = "";
    8.    
    9.         // search for "-assetBundleName" arg in the array
    10.         for (int i = 0; i < args.Length; i++)
    11.         {
    12.             if (args[i] == "-assetBundleName")
    13.             {
    14.                 assetBundleName = args[i + 1];
    15.                 break;
    16.             }
    17.         }
    18.    
    19.         AssetBundleBuilder.Build(assetBundleName);
    20.     }
    21. }
    With UCmd, this gets a lot simpler - just define the method you want and it will get called from the command line with the required parameters:
    Code (CSharp):
    1. public static class Builder
    2. {
    3.     public static void BuildAssetBundle(string assetBundleName)
    4.     {
    5.         AssetBundleBuilder.Build(assetBundleName);
    6.     }
    7. }
    How to use
    Integration is very quick and simple. Consider the command line that was previously used to run Unity (build target is Android, use whatever platform you need):
    Unity.exe -buildTarget android -projectPath xxx -batchmode -quit -executeMethod Builder.BuildAssetBundle

    With UCmd (changes highlighted):
    Unity.exe -buildTarget android -projectPath xxx -batchmode -quit -executeMethod UCmd.Run Builder.BuildAssetBundle myAssetBundle

    Target Audience
    Developers using Unity from the command line for various tasks - automation, build servers, asset bundle and content building and so on.

    Limitations
    Currently, only static methods are supported with primitive arguments (int, bool, char, long, double, float, string).

    Do you have any questions, comments or feature requests? feel free to comment, PM me or drop me an email.
     

    Attached Files:

    Last edited: Oct 10, 2018
    henriqueranj and De-Panther like this.
  2. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    since you plugged this from another thread on a similar topic:

    I HIGHLY recommended to use the -buildTarget <targetName> option when doing a build from command line such as this. This is so Unity is launched with the Editor in the same target as what you are trying to build.
     
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Thanks, that was just an example. I edited the original post to use that option as well.
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    UPDATE: The package has been recently updated to v0.3 with a new feature to facilitate setting PlayerSettings for your command line builds.

    Example - setting bundleVersion from command line arguments:
    Code (CSharp):
    1.  
    2. public static class Builder
    3. {
    4.     public static void Build
    5.     {
    6.         // This will pass on all command line arguments and attempt to set any properties on the PlayerSettings class.
    7.         UCmd.SetPlayerSettings();
    8.  
    9.         // Build your game as usual (e.g: BuildPipeline.BuildPlayer)
    10.     }
    11. }
    Then execute Unity using the following command line arguments to set the bundleVersion:
    Unity.exe -executeMethod Builder.Build bundleVersion 0.42

    Any public (settable) property on the PlayerSettings class is supported. see the class documentation for more information.

    Enjoy, and as always, let me know if this asset is useful for you, and whether you'd like to see any other features in it!