Environments (please complete the following information):
- UniVRM version:
0.130.1
- Unity version:
Unity-6000.2.9
- OS:
Windows 11
Describe the bug
- Try to import a glTF file in
Start in a URP project
- The model is magenta because it is using built-in shaders
When importing a glTF file at runtime on the first frame, the default MaterialDescriptorGeneratorUtility.GetValidGltfMaterialDescriptorGenerator() uses RenderPipelineUtility.GetRenderPipelineType() which is not guaranteed to be valid for around 4 frames: https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Rendering.RenderPipelineManager-currentPipeline.html. This results in it thinking it's running in the built in pipeline and choosing those shaders.
public class Test : MonoBehaviour
{
public string FilePath;
GltfData data;
GameObject go;
public void Start()
{
data = new AutoGltfFileParser(FilePath).Parse();
using (var context = new ImporterContext(data))
{
var loaded = context.Load();
loaded.ShowMeshes();
go = loaded.Root;
go.transform.SetParent(this.transform, false);
}
}
}
The fix looks like it should just be using GraphicsSettings.currentRenderPipeline instead.
A work around for this is to provide the URP material generator directly:
...
using (var context = new ImporterContext(data, materialGenerator: new UrpGltfMaterialDescriptorGenerator()))
...
Environments (please complete the following information):
0.130.1Unity-6000.2.9Windows 11Describe the bug
Startin a URP projectWhen importing a glTF file at runtime on the first frame, the default
MaterialDescriptorGeneratorUtility.GetValidGltfMaterialDescriptorGenerator()usesRenderPipelineUtility.GetRenderPipelineType()which is not guaranteed to be valid for around 4 frames: https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Rendering.RenderPipelineManager-currentPipeline.html. This results in it thinking it's running in the built in pipeline and choosing those shaders.The fix looks like it should just be using
GraphicsSettings.currentRenderPipelineinstead.A work around for this is to provide the URP material generator directly: