https://files.sshnuke.net/zz_office02_s06.eprf.fbx
In this FBX i have the following materials: ~152_Skin00, ~151_Skin01, ~14Z_Skin02, ~150_Skin03, ~154_Skin04, ~153_Skin05, ~0wl_Skin06, ~04d_Skin07, ~060_Skin08, ~14Y_Skin09, ~155_Skin10
BaseLOD uses Skin00, Skin01, Skin02, Skin03, Skin04, Skin05, Skin06, Skin07, Skin08
LOD1 uses Skin00, Skin01, Skin02, Skin03, Skin04, Skin05, Skin06, Skin07, Skin08 (same as baselod)
LOD2 uses Skin09 (simplified low res texture atlas covering the entire object)
So, I depend on the material order being correct to programmatically switch building skins and such for variety.
I expected the StaticMesh->Materials array (for when you set them per instance) to be of length 10 (0-9, as 10 isnt used), and have them in the correct SkinXX order as specified in the FBX.
What i got was this: ~152 (Skin00), ~151 (Skin01), ~14Z (Skin02), ~150 (Skin03), ~154 (Skin04), ~153 (Skin05), ~0wl (Skin06), ~04d (Skin07), ~060 (Skin08), ~152 (Skin00), ~151 (Skin01), ~14Z (Skin02), ~150 (Skin03), ~154 (Skin04), ~153 (Skin05), ~0wl (Skin06), ~04d (Skin07), ~060 (Skin08), ~14Y (Skin09)
(Easiest way to view this array is just to import the static mesh, obviously with LODs enabled and materials enabled, then “Asset Actions->Create Blueprint from this”, and then look at the Materials array on the StaticMeshComponent)
It’s obvious what’s happening here, the SkinXX sorting and deduplicating is happening as if the LODs were imported separately, which is exactly what i wanted to avoid by putting them all in one FBX file iwth LODGroups. More accurately, it happens inside ImportStaticMeshAsSingle which is run once for each LOD index (and without any context from other LODs), regardless if the LODs are in one fbx or not, so the SkinXX sorting is happening PER LOD, then those skins are ADDED to the materials array, so you get duplicate materials in the array if more than one LOD uses it (and the order could also be incorrect, it isn’t in this case, but it would be if LOD0 was using Skin09 before any others were)
I’ve tried to refactor that method so that the material remapping happens after all the LODs have been imported in a separate method, but the logic is too obfuscated for me to follow correctly, too much of it relies on only importing one LODIndex at a time.
So could you guys help me out by fixing this behaviour to work across LODs as I expect it to ?