Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Making subscene builds from script.

Discussion in 'Entity Component System' started by Dan-Foster, Mar 26, 2021.

  1. Dan-Foster

    Dan-Foster

    Joined:
    Aug 7, 2019
    Posts:
    48
    Hi there,

    I'm working on a project that's using NetCode and Entity Subscenes. I'm looking to make builds with Jenkins atm and I'm trying to make a server + client builds through a script.

    So far I'm able to make builds manually by using the .buildconfiguration assets through Assets > Create > Build > Windows Classic Build Configuration. Adding the scenes I need, headless mode, etc etc. These builds are coming out how I want them.

    I'm wondering if there's a way to trigger the build functionality of these Build Configurations in a script so that I can make builds which use SubScenes in Jenkins.

    Thanks,
    Dan
     
  2. Lukas_Kastern

    Lukas_Kastern

    Joined:
    Aug 31, 2018
    Posts:
    97
    The BuildConfiguration class has a method called Build which you should be able to use
     
  3. Dan-Foster

    Dan-Foster

    Joined:
    Aug 7, 2019
    Posts:
    48
    So I've found the file "com.unity.platforms@0.10.0-preview.10\Editor\Unity.Build\BuildConfiguration.cs" but I'm unable to get access to it in my Build script.

    If I do
    Code (CSharp):
    1. Unity.Build.BuildConfiguration buildConfiguration = new Unity.Build.BuildConfiguration();
    I simply get an error saying that 'BuildConfiguration' does not exist.

    I have the build script in an Editor folder, do I need to put my build script in a special folder to gain access to the Unity.Build namespace?

    Thanks
     
    Lontis likes this.
  4. Lontis

    Lontis

    Joined:
    Sep 10, 2017
    Posts:
    5
    Did you manage to find the solution to this?
     
  5. Dan-Foster

    Dan-Foster

    Joined:
    Aug 7, 2019
    Posts:
    48
    No I'm afraid not. I'm still creating builds manually for this project atm.

    Something I did notice was that the Scriptable Build Pipeline package had an update so it might have been the cause of my problem.
     
  6. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    You have to find the actual asset you want to build from. example:

    Code (CSharp):
    1.  
    2. var buildSettings = (BuildConfiguration)AssetDatabase.LoadAssetAtPath("Packages/com.thelebaron.BuildTools/game.buildconfiguration", typeof(BuildConfiguration));
    3.          
    4. //Assert.IsNotNull(buildSettings);
    5. buildSettings.Build();
    The path should be wherever your particular BuildConfiguration resides in your project. I happen to have mine in a package folder but it can be inside your assets folder.
     
    Lukas_Kastern likes this.
  7. Lontis

    Lontis

    Joined:
    Sep 10, 2017
    Posts:
    5
    The issue is still there as soon as you hit save and return to Unity. Unity does its compiling and reloading and you are met with:

    upload_2021-6-20_21-34-30.png

    and (rider):

    upload_2021-6-20_21-33-18.png
     
  8. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    First double check you have the DOTS platforms package installed.
    For instance on a windows desktop project I have the following installed, cant remember whats done through hidden dependencies but here they are(this will be depend on the platform you are building on):
    com.unity.platforms

    com.unity.platforms.desktop

    com.unity.platforms.windows


    Then create a build configuration file "Assets > Create > Build > Windows Classic Build Configuration"

    After that you will need to figure out your own configuration's path. I dont recall if the AssetDatabase automatically includes the Asset folder in the path or not but it should be easy to try.
    var buildSettings = (BuildConfiguration)AssetDatabase.LoadAssetAtPath("YourPathTo/YourBuildConfiguration.buildconfiguration", typeof(BuildConfiguration));


    Anyway just to reiterate, the path names are totally dependent on your own file naming and folder conventions.
     
  9. artur_orbital

    artur_orbital

    Joined:
    Nov 27, 2019
    Posts:
    1
    Hi there,
    I got exactly the same problem, and none of the replays help.
    I got all packages, and same as others can't reference the BuildConfiguration class.

    com.unity.platforms
    com.unity.platforms.desktop
    com.unity.platform.windows
    com.unity.platform.macos
    com.unity.platform.ios


    and so on...
    I am actually trying to build for ios, but neither ios nor macos build settings are working.

    error CS0246: The type or namespace name 'BuildConfiguration' could not be found (are you missing a using directive or an assembly reference?)
     
  10. Lukas_Kastern

    Lukas_Kastern

    Joined:
    Aug 31, 2018
    Posts:
    97
    Unity.Build isn't automatically referenced. You have to reference it in a custom assembly definition.
     
  11. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    Sorry, could you (or someone else) break this down step-by-step for me? I'm very unfamiliar with Custom Assembly Definitions - I create a Custom Assembly Definition asset (where?) and set its values (to what?)

    I'm not used to having to link up a package I've installed from the manager to be able to access its contents in a script.
     
  12. Dan-Foster

    Dan-Foster

    Joined:
    Aug 7, 2019
    Posts:
    48
    Hello @Matt-Cranktrain

    I've just revisited this after seeing your comment. I was also a bit lost based on that comment and didn't bother looking into it at the time.

    BUT! I did google what a custom assembly definition is. And found out what I needed to do to get the Unity.Build stuff accessible in my code.

    What I have right now that works is, I have my build script in an Editor folder, and then along side it I have an Assembley Definition Reference file. I've created the Assembly Def ref file by right clicking in the folder > Create > Assembly Definition Reference.
    upload_2021-10-29_20-21-56.png
    Then in the Inspector I've added Unity.Build so it looks like this:
    upload_2021-10-29_20-22-37.png
    And now my build script looks like this :
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using Unity.Build;
    4.  
    5. public class BuildManager
    6. {
    7.     [MenuItem( "Builds/Build Client" )]
    8.     public static void BuildClient()
    9.     {
    10.         Debug.Log( "Building Client" );
    11.         var buildSettings = (BuildConfiguration)AssetDatabase.LoadAssetAtPath( "Assets/Build Configs/ClientBuild.buildconfiguration", typeof( BuildConfiguration ) );
    12.         // Test
    13.         buildSettings.Build();
    14.     }
    15. }
    16.  
    Now I can use my own menu button to make a client build!

    I hope this helped!
     
    bb8_1 and Matt-Cranktrain like this.
  13. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    Thanks Dan! I just figured it out by not creating an Assembly Definition Reference but rather an Assembly Definition (sans 'Reference') asset and referenced Unity.Build in the list:

    Assembly.png

    I assume this is... pretty much identical to what you've described.

    I wonder why this is the way things are! At the very least there could be some official docs around this.
     
    bb8_1 and Dan-Foster like this.
  14. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,218
    It's listed in a few places.

    "You must set explicit references in the assembly definition file to other assemblies (whether in the same package or in external packages)."
    https://docs.unity3d.com/Manual/cus-asmdef.html

    "Referencing another assembly
    To use the C# types and functions that are part of another assembly, you must create a reference to that assembly in the Assembly Definition asset."
    https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html (About halfway down the page)
     
  15. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    Yes, of course the documentation for Assembly Definition Refences is going to have some information about Assembley Definition References. I mean that to use Unity.Build in your scripts, you have to link it by assembly reference - that's what should be in the docs, again, specifically the Platform or Build manual docs.

    The manifest for my project uses a few dozen packages and I've never had to directly reference them before - this thread from Dan and all the other contributors should be evidence enough that this isn't documented sufficiently.