On our iOS build, all the textures included in Universal RP are in memory, but our project doesn’t reference them, even indirectly. They are all referenced by (only) PostProcessData included in URP, but all of our ForwardRendererData scriptable objects do not reference PostProcessData, and we aren’t using the ForwardRendererData scriptable object that is in the URP package.
We are using Unity 2019.4.10f1, URP 7.5.1 and Addressables 1.16.1, building to iOS 13.
It even seems we have two copies of all these textures in memory, although we are packing all our addressable groups separately, and ran the deduplication rule… and pack that group separately… and don’t use post processing at all.
Xcode attached to the device build (GPU Capture memory view)
Here you can see I confirmed that a sample of these textures are only referenced in the project by the scriptable objects included in URP seen here, and not by any assets we use:
Here is the code to walk the references, as output in the console:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class FindReferencesInProject
{
private const string MenuItemText = "Assets/Find References In Project";
[MenuItem(MenuItemText, false, 25)]
public static void Find()
{
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
var referenceCache = new Dictionary<string, List<string>>();
string[] guids = AssetDatabase.FindAssets("");
foreach (string guid in guids)
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
string[] dependencies = AssetDatabase.GetDependencies(assetPath, false);
foreach (var dependency in dependencies)
{
if (referenceCache.ContainsKey(dependency))
{
if (!referenceCache[dependency].Contains(assetPath))
{
referenceCache[dependency].Add(assetPath);
}
}
else
{
referenceCache[dependency] = new List<string>(){ assetPath };
}
}
}
Debug.Log("Build index takes " + sw.ElapsedMilliseconds + " milliseconds");
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
Debug.Log("Find: " + path, Selection.activeObject);
if (referenceCache.ContainsKey(path))
{
foreach (var reference in referenceCache[path])
{
Debug.Log(reference, AssetDatabase.LoadMainAssetAtPath(reference));
}
}
else
{
Debug.LogWarning("No references");
}
referenceCache.Clear();
}
[MenuItem(MenuItemText, true)]
public static bool Validate()
{
if (Selection.activeObject)
{
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
return !AssetDatabase.IsValidFolder(path);
}
return false;
}
}
From GitHub - networm/FindReferencesInProject: Find asset references in Unity project. Faster version: https://github.com/networm/ReferenceFinder
I blame the code in ForwardRendererData.cs, which seems to make it impossible for me to set the PostProcessData to None without maybe inheriting from ForwardRendererData and overriding the methods that reload, and undo my inspector changes
[Reload("Runtime/Data/PostProcessData.asset")]
public PostProcessData postProcessData = null;
We don’t use dithering, we don’t use SMAA, we don’t use film grain… we shouldn’t need all these MB of textures taking up memory.
ugh, spent way to much time figuring this out, and my fix probably won’t last a point release. What we really need is the ability to strip all the PostProcessing textures and shaders from a build. URP and Unity are typically for mobile and most mobile titles are going to benefit from avoiding all post…
EDIT: Unity has a fix in progress to allow stripping post shaders and textures, but it isn’t in a 2019 release yet
(if you point all your forward renderers to a custom PostProcessing asset and go into debug and clear out the textures, then this script will prevent them from reloading… for now)
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
#endif
using System;
using UnityEngine.Rendering.Universal;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEngine.Rendering.Universal
{
//[CreateAssetMenu(fileName = "ForwardRenderingDataNoPost.asset", menuName = "ScriptableObjects/ForwardRenderingDataNoPost", order = 3)]
[Serializable, ReloadGroup, ExcludeFromPreset]
public class ForwardRendererDataNoPost : ForwardRendererData
{
#if UNITY_EDITOR
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812")]
internal class CreateForwardRendererNoPostAsset : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
var instance = CreateInstance<ForwardRendererDataNoPost>();
AssetDatabase.CreateAsset(instance, pathName);
ResourceReloader.ReloadAllNullIn(instance, UniversalRenderPipelineAsset.packagePath);
Selection.activeObject = instance;
}
}
[MenuItem("Assets/Create/ScriptableObjects/ForwardRenderingDataNoPost", priority = 0)]
static void CreateForwardRendererData()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateForwardRendererNoPostAsset>(), "CustomForwardRendererNoPostData.asset", null, null);
}
#endif
protected override ScriptableRenderer Create()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
ResourceReloader.TryReloadAllNullIn(this, UniversalRenderPipelineAsset.packagePath);
}
#endif
return new ForwardRenderer(this);
}
//#if UNDEFINED
protected override void OnEnable()
{
SetDirty();
// Upon asset creation, OnEnable is called and `shaders` reference is not yet initialized
// We need to call the OnEnable for data migration when updating from old versions of UniversalRP that
// serialized resources in a different format. Early returning here when OnEnable is called
// upon asset creation is fine because we guarantee new assets get created with all resources initialized.
if (shaders == null)
return;
#if UNITY_EDITOR
ResourceReloader.TryReloadAllNullIn(this, UniversalRenderPipelineAsset.packagePath);
#endif
/*
base.OnEnable();
#if UNITY_EDITOR
postProcessData.textures = null;
#endif
*/
}
//#endif
}
}
1 Like
@chrismarch_1 , did you happen to have a current solution for this in 2020.3? We had a workaround script that seemed to be working in 2019.4, but this year Unity seems to be overwriting our changes and forcing unneeded post-processing textures back into the build.
Note: We’d rather not disable Post-Processing completely, but we certainly don’t need all these big, uncompressed, FilmGrain textures. So silly that they’re automatically included in a way you can’t disable, resize or at least crunch.