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

AutoLOD breaks the asset importer when creating a scene via C# #85

Closed neitron closed 2 years ago

neitron commented 2 years ago

I'm trying to create and save a new scene via EditorSceneManager.SaveScene. When the new scene is created and imported it doesn't appear in the Project panel but is visible in the file system. AssetDatabase.Refresh didn't help. I've spent a whole day debugging my code and surfing the project without any success. Only this line of code is an issue EditorSceneManager.SaveScene which is unity API. Then I wasted even more time looking for any related unity bugs. No results. I was so frustrated so I've decided to create an empty project and test it there. And it worked. So the next idea was to import all the packages one by one to see if any of them may cause the issue. And AutoLOD did. To be sure I've created another empty project with AutoLOD added only and reproduced the bug. I also tried to disable all the AutoLOD automatic options in the preferences which didn't help to solve the issue.

I'm working in Unity 2020.3.14f1 running on MBP Retina 2015 (Intel i7) with macOS BigSur 11.2.1.

Steps to reproduce:

public class TestWindow : EditorWindow { [MenuItem("Test/SceneCreator")] private static void Init() { var window = (TestWindow)EditorWindow.GetWindow(typeof(TestWindow)); window.Show(); }

private void OnGUI()
{
    if (GUILayout.Button("Create and Save"))
        TestNewSceneCreateAndSave();
}

private void TestNewSceneCreateAndSave()
{
    var sceneName = "TestScene";
    var path = Path.Combine("Assets", "Scenes", $"{sceneName}.unity");

    var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);

    if (AssetDatabase.DeleteAsset(path))
        Debug.Log($"A scene with the same name has been removed. Path: {path}");

    if (EditorSceneManager.SaveScene(scene, path, true))
    {
        Debug.Log($"A new scene has been created. Path: {path}");
    }
}

}


- Open the test window 'Test -> SceneCreator'
- Hit the button 'Create and Save'
- Try to reimport any file in the project, its icon will disappear

In case you do not reproduce it for the first time, remove a new generated scene from the hierarchy and hit the button again. repeat a few times and the asset importer will get broken. You will notice it when a new generated and saved scene will not appear in the scene folder in the Project panel. 

The editor log will spam an infinite amount of messages:
![Clipboard - November 24, 2021 6_03 PM](https://user-images.githubusercontent.com/10614636/143319887-a2a8dc05-9904-4faf-9ee0-90454a77f233.png)

And non responding process is appearing:
![Clipboard - November 24, 2021 6_12 PM](https://user-images.githubusercontent.com/10614636/143321285-cfb4a7c5-fa3c-4592-af12-146ac6ecc637.png)
amirebrahimi commented 2 years ago

Thank you for taking the time to send repro steps and I hear your frustration. Tracking down intermittent bugs can be time consuming.

I've tried your steps on Unity 2020.3.16f1 on Windows 11 by creating a new project, adding AutoLOD via the git url, copying your code into a script under Editor/TestWindow.cs, opening the window and repeatedly clicking the button and then removing the scene. In between I tried reimporting an fbx file. I tried multiple times, but cannot reproduce.

If this issue is still affecting you, could you try updating to Unity 2020.3.16f1 and see if it you can still get it to occur? I'm curious how we could get the issue to happen on the first try.

neitron commented 2 years ago

Hi, thanks for you response. Its a big commercial prj, we can't just update it. So far we removed the AutoLOD package, anyway we used the mesh simplifier mostly.

amirebrahimi commented 2 years ago

Understood. I wish I had been able to reproduce the problem in order to provide a fix. Since you've found a workaround I'll go ahead and close this issue. If you do ever try AutoLOD again and have a more stable repro, then feel free to re-open this issue.

neitron commented 2 years ago

What about reproducing it with the exact unity version I mentioned?

ср, 8 дек. 2021 г., 19:12 Amir Ebrahimi @.***>:

Understood. I wish I had been able to reproduce the problem in order to provide a fix. Since you've found a fix I'll go ahead and close this issue. If you do ever try AutoLOD again and have a more stable repro, then feel free to re-open this issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Unity-Technologies/AutoLOD/issues/85#issuecomment-989006741, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACQ7O3EQORDVKOGOXPDSXXLUP6GXRANCNFSM5IXEPNXQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

amirebrahimi commented 2 years ago

I can give that a try on Windows. Not sure if it is a Mac-only issue.

amirebrahimi commented 2 years ago

Tried on 2020.3.14.f1 and couldn't reproduce:

https://user-images.githubusercontent.com/904110/145273269-4d71e4c8-0af7-4449-93aa-23c76971e248.mp4

amirebrahimi commented 2 years ago

I also tried this on my Mac (macOS Big Sur 11.5) w/ Unity 2020.3.14f1 and couldn't reproduce the issue.