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.84k stars 215 forks source link

Limited number of objects possible to process at once with Simplygon #38

Closed Keeetrab closed 5 years ago

Keeetrab commented 6 years ago

Hey, Once I select more than ~15 objects to process at once, simplygon plugin stops. Jobs are posted one by one I guess so why this happens. Any solution to automate it?

amirebrahimi commented 6 years ago

Hmm...Haven't seen this and currently the Simplygon plugin for Unity is unsupported. What version of the plugin/Simplygon are you using?

JangkyuSeo commented 6 years ago

I fixed the same problem. I guess a reason of problem is making too many threads.
When you using Simplygon, you should managing thread count to not making too many threads. My opinion is make thread pool and use it.

Keeetrab commented 6 years ago

I m using 2.5.1 version of Unity plugin and 8.2.359 Simplygon Lib.

I tried to count workers

                    var worker = new BackgroundWorker();            
                    workersWorking++;

and on worker.RunWorkerCompleted

                    worker.RunWorkerCompleted += (sender, args) =>
                    {
                        var resultMesh = (WorkingMesh)args.Result;
                        resultMesh.ApplyToMesh(simplifiedMesh);
                        simplifiedMesh.RecalculateBounds();

                        workersWorking--;

                    };. 

Then I tried to check how many workers are in GenerateLODsCoroutine()

        var go = menuCommand.context as GameObject;
        if (go)
        {                              
            while(workersWorking > 2)
            {
                yield return null;
            }
            GenerateLODs(go);

        }

However this, blocks whole Unity. Any tips how should I approach it?

JangkyuSeo commented 6 years ago

You should use yield return WaitForSecond(time) insted of yield return null.

Because TimedEnumerator is not stopped until pass the iteration time. It means that yield return null is not continue next frame. It will continue same frame.