You can use Dedicated Server as a target for content directory and AssetBundle builds.
To build content directories for a Dedicated Server, set EditorUserBuildSettings.standaloneBuildSubtarget to StandaloneBuildSubtarget.Server while the active build target is a desktop Standalone platform, then call BuildPipeline.BuildContentDirectory. For example:
// BuildContentDirectory uses the active build target and subtarget.
// Set the Dedicated Server subtarget before you build.
EditorUserBuildSettings.standaloneBuildSubtarget = StandaloneBuildSubtarget.Server;
var serverContentParameters = new BuildContentDirectoryParameters
{
outputPath = "Builds/ServerContent",
rootAssetPaths = new[] { "Assets/ServerContentRootAsset.asset" }
};
BuildPipeline.BuildContentDirectory(serverContentParameters);
After you build the content directory, distribute it alongside the server Player and register it at runtime to load its content. For more information, refer to Load content directories.
Important: A content directory build is specific to the active build target and subtarget. Build the content directory with the same platform and Dedicated Server subtarget as the server Player, and only load it in a matching Player.
To build an AssetBundle to undergo the same Dedicated Server optimizations as discussed for the Player, specify the subtarget field in the BuildAssetBundlesParameters struct to be StandaloneBuildSubtarget.Server when calling the BuildAssetBundle method. Refer to the following example:
BuildAssetBundlesParameters serverAssetBundleParameters =
{
outputPath = /*some example asset path here, not entirely relevant*/,
options = BuildAssetBundleOptions.None,
targetPlatform = BuildTarget.StandaloneWindows64, //alternately, the MacOS or Linux build targets, any desktop platform
subtarget = StandaloneBuildSubtarget.Server
};
BuildPipeline.BuildAssetBundles(serverAssetBundleParameters);
After you build the AssetBundle, you can load it by a Player at runtime. Refer to Using AssetBundles Natively.
Warning: While the AssetBundle loading process checks if the AssetBundle target platform matches the target platform of the Player, it doesn’t check the AssetBundle subtarget. Make sure not to load an AssetBundle that was built for a non-server standalone Player. Don’t try to load an AssetBundle that targets the Dedicated Server subtarget (or vice-versa).