Unity-Technologies / AutoLOD

Automatic LOD generation + scene optimization
https://blogs.unity3d.com/2018/01/12/unity-labs-autolod-experimenting-with-automatic-performance-improvements/
Other
1.81k stars 212 forks source link

Automatically generated LODs don't seem to work for more than one user. #84

Open chrispewebb opened 2 years ago

chrispewebb commented 2 years ago

When generating LODs in a project being used by more than one user, the LODs and prefabs which use the generated LODs do not work correctly/at all when being used on a computer they were not originally generated on.

It seems that because LODGroup data is stored on the imported FBX which is an "internal asset" (as I understand), it is stored in the library, rather than the project, which means all users get their own unique local prefab, with unique links to meshes stored in the _lods asset.

As a result, it seems LODs generated on import on one computer do not work on any other computer, and the LODgroup simply has links to mesh renderers with missing meshes if they did not generate the LODs initially.

One potential solution may involve checking if _lods have been generated on import of the fbx, and linking with the imported lods rather than not generating anything or generating new lods. This may impact other elements of the system however.

missingmesh
amirebrahimi commented 2 years ago

Were the LODs included in the FBX or are they getting generated by the AutoLOD package? If AutoLOD is generating them, then there should be a <file>_lods.asset file that sits next to the FBX. Make sure to "Save All" in Unity and check that file in with your project.

Or are you talking about importing an FBX from another package? If that is the case, then that may currently be unsupported because my guess is that the FBX would create a *_lods.asset file in the local packages directory.

chrispewebb commented 2 years ago

Hello,

Thanks for the reply.

The fbx did not include LODs. LODs (the _lods file) were generated during import by the AutoLOD package. The _lods file was submitted to version control with the fbx file on computer A.

When imported on computer B, the fbx file prefab loses references to the meshes in the _lods file, and all lod levels other than 0 are invisible.

Thanks

chrispewebb commented 2 years ago

A secondary negative thing that happens when using lods on more than 1 computer is that the _lods file is automatically modified by compute B, then when the modified file is committed and imported on computer A, the lods on computer A then also break.

chrispewebb commented 2 years ago

I have debugged a bit of what happens during the import in the second computer, and it seems like when the fbx and the _lods assets are imported at the same time, the fbx is imported first and "GetLODData" always returns null during LoadAssetAtPath, because the _lods asset has not yet been imported. This causes the file to essentially be generated over itself, modifying it.

Im not sure if there is a way in Unity to order scriptable object imports before fbx imports though. Force importing the lods path prior to loading didnt seem to help.

None of this would solve the issue of unlinked meshes, however. That may require linking to the already generated lod meshes via name, if the exist, or generating them new if then don't.

amirebrahimi commented 2 years ago

Hmm..This is odd. Do you mind sending me a sample project or the fbx file? If you need to email it you can send to amir at unity3d. What version of Unity are you using and are you using the latest version of this package?

chrispewebb commented 2 years ago

Hello,

I will happily send you a repro project.

I am using Unity version 2021.2.3f1 with the latest version of the AutoLOD Package.

The attached project is a fresh project + AutoLOD, with a single model added. The scene "SampleScene" contains the model. I have not included my library folder for the sake of reproducing this issue. (and size :)

On my computer, the model in the scene has working LODs.

When you open the project, the model should have non-functional LOD levels.

To reproduce this issue repeatedly, simply copy the project to a new location, delete the library folder, then open it again. This will simulate a different user with a unique local library.

For the sake of being certain about the issue, I have also tested it several times using a full version control process on several computers + several repos on the same computer, but thats obviously a bit more painful to test :)

I have noticed that sometimes the model in the scene has meshfilters with "Missing" models, (as in the image in my original post), but other times it actually has links to empty lod meshes. This is probably caused by the "generate on import" setting on the _lods asset (I have not looked into this much, I only just noticed). In both cases, it seems that the _lods asset is modified anyway, making it incompatible with version control.

AutoLODTest.zip

Thanks for the assistance.

amirebrahimi commented 2 years ago

This seems to be a compatibility issue with 2021.2 and may take a bit more time to track down. So, it is less about a missing reference and more about the lods never getting generated to begin with. As you mentioned, too, in 2021.2 you'll see that if you delete the _lods.asset and reimport that there are empty lods.

When I go back to 2019.4.29f1 and reimport I get this: image

amirebrahimi commented 2 years ago

I tested on 2020.3.16f1 and it also worked. I went back to 2021.2.2f1 and saw the problem again, so I tried importing another model and the same issue happens with it, too. So, it looks like at the moment AutoLOD does not work with 2021.2.

andreiagmu commented 2 years ago

@amirebrahimi Any update about this issue? I tested @chrispewebb's repro project on Unity 2021.2.6f1 and the issue still happens (a bit differently, it seems).

On this version of Unity, if I delete the _lods.asset and reimport the model, then the LODs are generated correctly. But if I copy the project to another location, and delete the Library folder (as chrispewebb explained above), then the lods are empty again when I open the new project.

By the way, this message appeared on the console after the repro project was opened for the first time:

The model has an existing lod group, but it's settings will not be used because the specified lod count in the AutoLOD settings is different. UnityEngine.Debug:LogWarning (object) Unity.AutoLOD.ModelImporterLODGenerator:OnPostprocessModel (UnityEngine.GameObject) (at Library/PackageCache/com.unity.autolod@9492bc0620/Editor/ModelImporterLODGenerator.cs:284) UnityEditor.AssetPostprocessingInternal:PostprocessMesh (UnityEngine.GameObject)

andreiagmu commented 2 years ago

On this version of Unity, if I delete the _lods.asset and reimport the model, then the LODs are generated correctly.

I tested it again, now the LODs aren't being generated if I reimport the model / if I use AutoLOD -> Generate LOD option.

EDIT: Sometimes the LODs generation works, sometimes it doesn't work.

There was a test where I copied the project to another folder, deleted Library, and opened the new project, then the LODs I had generated before were correctly imported. But then I deleted the _lods.asset and regenerated the LODs, and the LODs were empty again.

It's all very inconsistent in Unity 2021.2.

EDIT 2: In my latest tests I disabled "Generate on Import" on AutoLOD Preferences, I'm manually using AutoLOD -> Generate LOD on the .fbx model. Maybe that's the reason the LOD generation/import appears to work correctly sometimes (doesn't fail 100% of the time).

amirebrahimi commented 2 years ago

@andreiagmu - No update on this; seems to be something that has broken (or at least changed) in Unity between 2020 and 2021. I haven't had a chance to dig any deeper on this.