Recently, when optimizing the memory, I found a shader with a very high memory
usage that is too bad. G
Observed by Profiler, shaderlab occupies 273M, which is very high (for a small project, only a few shaders are used in total).
The most used shader in the project is standard
. I did a test and replaced the standard
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class ExchangeMaterials : MonoBehaviour
{
[MenuItem("Tools/ExchangeMaterial")]
static void ExchangeMaterials()
{
var allMaterials = AssetDatabase.FindAssets("t: Material");
foreach (var guid in allMaterials)
{
var path = AssetDatabase.GUIDToAssetPath(guid);
Material m = AssetDatabase.LoadAssetAtPath(path, typeof(Material)) as Material;
if (m != null)
{
if (m.shader.name == "Standard")
{
m.shader = Shader.Find("AAA");
}
}
}
}
}
Find out all the standard in the project and replace them with test shaders. At this time, I found that some shaders could not be taken out and replaced.
After scratching my head for a while, I found that it was related to the settings of FBX import.
Setting parameters like this will generate a material that comes with the model, and you can change the shader La
After repackaging, I found that the package output speed was many times faster. I had a premonition that I must have found the direction this time. O(∩_∩)O haha~ After running, the
memory has been reduced by 600M+, and the memory has finally dropped. I also have lingering fears. I didn’t expect A small detail that was not observed takes up so much memory! ! ! Look at Profiler at this time, shaderlab occupies only 1.1M,,,