From 422f892af8ebde483b8fc8f1db19664577204a37 Mon Sep 17 00:00:00 2001 From: Zain / Kaiser M <106357974+KaiserM21@users.noreply.github.com> Date: Mon, 30 Oct 2023 18:52:40 +0100 Subject: [PATCH] Fix Overwrite Material Index --- FModel/Views/Snooper/Renderer.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/FModel/Views/Snooper/Renderer.cs b/FModel/Views/Snooper/Renderer.cs index b66ea124..5f2b8e22 100644 --- a/FModel/Views/Snooper/Renderer.cs +++ b/FModel/Views/Snooper/Renderer.cs @@ -517,13 +517,11 @@ public class Renderer : IDisposable if (staticMeshComp.TryGetValue(out FPackageIndex[] overrideMaterials, "OverrideMaterials")) { - var max = model.Sections.Length - 1; - for (var j = 0; j < overrideMaterials.Length; j++) + for (var j = 0; j < overrideMaterials.Length && j < model.Sections.Length; j++) { - if (j > max) break; - if (!model.Materials[model.Sections[j].MaterialIndex].IsUsed || - overrideMaterials[j].Load() is not UMaterialInterface unrealMaterial) continue; - model.Materials[model.Sections[j].MaterialIndex].SwapMaterial(unrealMaterial); + var matIndex = model.Sections[j].MaterialIndex; + if (!(model.Materials[matIndex].IsUsed && overrideMaterials[matIndex].Load() is UMaterialInterface unrealMaterial)) continue; + model.Materials[matIndex].SwapMaterial(unrealMaterial); } }