Hi,
Recently, I’ve been a lot of issues with memory using LoadSceneAsync with regular built scenes, where the terrainData was staying in memory after being unloaded.
So, I’ve changed it all to use Addressables.
I’ve set all my streamed scenes to Addressables, and went over to the Groups window to make sure every scene was in its own Group. I’ve also set them at “Packed Separately”.
I’ve also took all my 5 shaders that these scenes might be using and marked them as Addressables, and created one single Group holding all of them, also set as “Packed Separately”
For my builds, I’m using Jenkins, and when I build, it runs the script BuildProcess.cs that runs this function:
static public void BuildAddressables()
{
#if UNITY_ADDRESSABLES
Debug.Log("BuildProcess :: Packaging Addressables.");
AddressableAssetSettings.CleanPlayerContent();
AddressableAssetSettings.BuildPlayerContent();
BuildCache.PurgeCache(false);
#endif
}
#endregion
It’s called here:
static BuildProcess()
{
//Build Process pre
BuildPlayerWindow.RegisterBuildPlayerHandler(
buildPlayerOptions => {
BuildAddressables();
BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(buildPlayerOptions);
});
}
And here:
private static BuildProcessData PreBuildPlatform(BuildTargetGroup targetGroup, BuildTarget target, string defaultExportPath, string[] arguments)
{
var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(targetGroup);
BuildProcessData data = new BuildProcessData();
data.arguments = ParseArguments(arguments);
data.target = target;
SetPlayerSettings(data);
SetBuildVariables(data);
SetGameVersion(data);
SetSteamAppId(data);
if (SetDedicatedDefineIfRequired(data.target, data.GetValueOrDefault("dedicatedServer", string.Empty)))
{
Debug.Log($"{LOGHEADER} Dedicated server detected for {target} :: Using EnableHeadlessMode to enable Dedicated Server");
data.buildOptions |= BuildOptions.EnableHeadlessMode;
data.subTarget = (int)StandaloneBuildSubtarget.Server;
namedBuildTarget = NamedBuildTarget.Server;
}
EditorUserBuildSettings.SwitchActiveBuildTarget(namedBuildTarget, target);
data.scenes = collectBuildScenes(data);
data.buildOptions = GetBuildOptions(data);
BuildAddressables();
ForceReserializeVFX();
//Checkout files that are required for Il2CPP
CheckoutFilesListing();
//Outbrk specific code:
CreateLightBuild.SetLightBuildValueTo(false);
data.exportPath = data.GetValueOrDefault("BuildDir", defaultExportPath);
return data;
}
Now, when I build, there are no apparent errors, the build succeeds, but then there are no “aa” folder where all my bundle files would be. So of course, the game cannot load the scenes when it’s trying to.
A weird thing is that prior to doing this to my scenes, I had addressables for some data in my game and it was working perfectly. These were in separate Groups (and still are) and they are set to “Packed Together” since they only get loaded all at once one time during gameplay and no other ones are going to get loaded for that type of files.
We really need to fix this to push a critical update to our released game, and I can’t seem to understand why my builds are not creating the bundle files.
Some details in case it’s important:
Since I have thousands of these scenes, I have created the Groups using an editor script that did the following:
- First, I set all of the scenes to Addressables. That put them in the Default Group, which was empty before that.
- Then I ran this script:
private void SplitDefaultLocalGroupAddressables()
{
// Get the Addressable settings
AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
// Find the Default Local Group
AddressableAssetGroup defaultGroup = settings.groups.Find(group => group.Name == "Default Local Group");
if (defaultGroup == null)
{
Debug.LogError("Default Local Group not found!");
return;
}
// Create a list to store the entries (to avoid modifying the collection while iterating)
List<AddressableAssetEntry> entriesToMove = new List<AddressableAssetEntry>(defaultGroup.entries);
// Iterate through the entries in the Default Local Group
foreach (var entry in entriesToMove)
{
// Create a new group for each entry
AddressableAssetGroup newGroup = CreateNewGroupForEntry(settings, entry, defaultGroup);
// Move the entry to the new group
settings.MoveEntry(entry, newGroup);
}
Debug.Log("Split complete!");
}
private AddressableAssetGroup CreateNewGroupForEntry(AddressableAssetSettings settings, AddressableAssetEntry entry, AddressableAssetGroup defaultGroup)
{
// Create a new group with the same name as the entry
string newGroupName = entry.address.Split(".unity")[0];
AddressableAssetGroup newGroup = settings.CreateGroup(newGroupName, false, false, true, defaultGroup.Schemas);
// Copy the schemas from the default group
foreach (var schema in defaultGroup.Schemas)
{
var newSchema = (AddressableAssetGroupSchema)ScriptableObject.CreateInstance(schema.GetType());
EditorUtility.CopySerialized(schema, newSchema);
newGroup.AddSchema(newSchema);
}
return newGroup;
}
Then, later on, I set them to “Pack Separately” in the editor.
Also, if that could matter, the Groups have rather long names, such as:
Assets-WorldStreamer-SplitScenes-outbrkSmallerTerrain-outbrkSmallerTerrain_x-2_z-4
Also, when I check my build logs, I can see that after building most of it, it goes over all the scenes again and compiles an internal hidden shader for every single one of them:
Loaded scene 'Assets/WorldStreamer/SplitScenes/outbrkSmallerTerrain/outbrkSmallerTerrain_x-28_z10.unity'
Deserialize: 8.967 ms
Integration: 590.331 ms
Integration of assets: 0.002 ms
Thread Wait Time: 0.017 ms
Total Operation Time: 599.318 ms
Unloading 122 unused Assets / (1.0 MB). Loaded Objects now: 30880.
Memory consumption went from 3.65 GB to 3.65 GB.
Total: 154.476200 ms (FindLiveObjects: 2.271100 ms CreateObjectMapping: 2.214400 ms MarkObjects: 148.790300 ms DeleteObjects: 1.199200 ms)
Unloading 88 Unused Serialized files (Serialized files now loaded: 0)
Unloading 0 unused Assets / (2.3 MB). Loaded Objects now: 30880.
Memory consumption went from 3.65 GB to 3.65 GB.
Total: 159.550300 ms (FindLiveObjects: 1.587100 ms CreateObjectMapping: 1.345500 ms MarkObjects: 156.530800 ms DeleteObjects: 0.085900 ms)
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/BillboardWavingDoublePass" pass "" (vp)
Full variant space: 3072
After settings filtering: 512
After built-in stripping: 4
After scriptable stripping: 2
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 2 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/BillboardWavingDoublePass" pass "" (fp)
Full variant space: 24576
After settings filtering: 4096
After built-in stripping: 32
After scriptable stripping: 4
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 4 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/BillboardWavingDoublePass" pass "DepthOnly" (vp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/BillboardWavingDoublePass" pass "DepthOnly" (fp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/BillboardWavingDoublePass" pass "DepthNormals" (vp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/BillboardWavingDoublePass" pass "DepthNormals" (fp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Serialized binary data for shader Hidden/TerrainEngine/Details/UniversalPipeline/BillboardWavingDoublePass in 0.00s
d3d11 (total internal programs: 10, unique: 10)
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit" pass "TerrainDetailVertex" (vp)
Full variant space: 3072
After settings filtering: 512
After built-in stripping: 8
After scriptable stripping: 2
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 2 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit" pass "TerrainDetailVertex" (fp)
Full variant space: 24576
After settings filtering: 4096
After built-in stripping: 64
After scriptable stripping: 8
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 8 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit" pass "TerrainDetailVertex - GBuffer" (vp)
Full variant space: 64
After settings filtering: 32
After built-in stripping: 8
After scriptable stripping: 4
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 4 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit" pass "TerrainDetailVertex - GBuffer" (fp)
Full variant space: 512
After settings filtering: 256
After built-in stripping: 64
After scriptable stripping: 8
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 8 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit" pass "DepthOnly" (vp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit" pass "DepthOnly" (fp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit" pass "DepthNormals" (vp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit" pass "DepthNormals" (fp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Serialized binary data for shader Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit in 0.00s
d3d11 (total internal programs: 26, unique: 26)
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/WavingDoublePass" pass "" (vp)
Full variant space: 3072
After settings filtering: 512
After built-in stripping: 4
After scriptable stripping: 2
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 2 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/WavingDoublePass" pass "" (fp)
Full variant space: 196608
After settings filtering: 16384
After built-in stripping: 128
After scriptable stripping: 8
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 8 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/WavingDoublePass" pass "DepthOnly" (vp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/WavingDoublePass" pass "DepthOnly" (fp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/WavingDoublePass" pass "DepthNormalsOnly" (vp)
Full variant space: 2
After settings filtering: 2
After built-in stripping: 1
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Compiling shader "Hidden/TerrainEngine/Details/UniversalPipeline/WavingDoublePass" pass "DepthNormalsOnly" (fp)
Full variant space: 4
After settings filtering: 4
After built-in stripping: 2
After scriptable stripping: 1
Processed in 0.00 seconds
starting compilation...
finished in 0.00 seconds. Local cache hits 1 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 0 variants (0.00s CPU time), skipped 0 variants
Prepared data for serialisation in 0.00s
Serialized binary data for shader Hidden/TerrainEngine/Details/UniversalPipeline/WavingDoublePass in 0.00s
d3d11 (total internal programs: 14, unique: 14)
I can’t mark this shader as Addressable to add it to my shared shaders Group, so I’m not sure what to do here.
That’s all I can think of. I really hope someone can help me!
Thank you SO much in advance.
