LogicalError / realtime-CSG-for-unity

Realtime-CSG, CSG level editor for Unity
https://realtimecsg.com
MIT License
786 stars 82 forks source link

[1.335] Very low editor frame rate when using both Realtime CSG and lots of your own models #148

Closed CodeCaster28 closed 7 years ago

CodeCaster28 commented 7 years ago

It is obvious that editor slows down when you have thousands of you own models in your scene. However even with ~300 models my editor works just fine, I always could temporarily turn off models so editor works like a charm so I might do other stuff w/o lags. However importing Realtime CSG plugin into this very scene makes it very hard to work with editor (low fps when rotating camera, a little more when only panning it). Disabling models by unticking their checkboxes doesn't help very much, only if you delete those models gradually from scene makes editors recovers it's normal fps.

I think there is an issue with CSG editor script(s). I looked into the Profiler to see more details about this issue, I listed possible scenarios with profiler report:

-with models removed:

200fps when not moving view, 100-200fps when rotating view,
Time (ms): scripts 2, rendering 1 when not moving view scripts 6, rendering 1 when rotating view

-after pressed undo to retrieve deleted models, situation gets even worse don't know why: 17fps when not moving view, 5-10fps when rotating view,
Time (ms): scripts 34, rendering 24 when not moving view scripts 56, rendering 25 when rotating view

-finally I removed Realtime CSG and tested again with models turned ON: 90fps when not moving view, 40fps when rotating view,
Time (ms): rendering and script close to 0 when not moving view scripts 4, rendering 18 when rotating view

So I'm sure there is some conflict between Realtime CSG and models imported to scene. The scripts takes most of CPU usage, the DockArea.OnGui() command to be precise, it's almost 100% of scripts usage, and 60% to 90% of whole CPU. przechwytywanie

Other info that may be useful:

1) If I remove all others assets from scene and project files leaving just models and textures plus RCSG the bug still persists. So this must be a conflict with my meshes and RCSG plugin.

2) When opening a new scene after opening the project the issue is not occurring, but when I go into scene with lot of models then go back again into that empty scene, strangely the issue still persists.

3) It is not required to put any CSG brushes on a scene, the problem starts when I import RCSG or open the editor with already imported RCSG. Clearing Liblary folder isn't working.

4) Models are in FBX format, the way editor imports them lets me edit different part of the models separately (maybe this counts as even more models).

4) Game FPS is very high, so issue is not affecting a gameplay itself.

6) Other things I tried to do to fix the issue:

Maybe CSG scripts uses meshes from my scene to compute something? All tests above I made w/o placing single CSG brush on scene, problem starts when editor loads plugin. No error messages/warnings are shown.

Tested at Windows 7, Unity version 5.4.2f, Realtime CSG version 1.333

LogicalError commented 7 years ago

When you say "models", do you mean CSG models? or unity meshes? .. just making sure Are you saying you have 300 unity meshes in your scene? It might be some code that (somehow) doesn't scale with lots of meshes in the scene .. I need to do a lot of work to work around Unity limitations .. Also, fyi you can enable/disble Realtime-CSG with Ctrl-F3.

LogicalError commented 7 years ago

Ok .. I just created a scene that contains Realtime-CSG and created 780 meshes (390 fbx models, all the same one) and it was still fine on my computer ... so I need some more information to figure out what's going on :-/ There must be a factor that's different for you somehow ...

CodeCaster28 commented 7 years ago

It's about 300 unity meshes made from fbx models. Tried reenabling and reimporting, no luck on that.

LogicalError commented 7 years ago

Can you check if you see any performance difference between having the tools in the scene and if the tool windows are docked? (control-F2 to switch between them)

CodeCaster28 commented 7 years ago

Amazing, yes this is the cause, why I didn't tried it before :D, so I "undocked" UI elements and fps rises to stable 60 again, profiler says the same thing.

LogicalError commented 7 years ago

cool, then I'm confident that I know what was going on :)

I was using a particular function to find the current window .. and apparently it goes through ALL the assets in a project, and it's really slow .

I didn't notice since I don't have as many assets in my projects .... :-/

I wrote a workaround: version 1.335 , which you can find at https://prenominal.nl/updates/ Let me know if that fixes it for you!

CodeCaster28 commented 7 years ago

I'm surprised you found and fixed this issue that fast. I thought this is meshes issue cause removing any other assets brings no fix for this. Thank you very much for this I can get back to level design :)

LogicalError commented 7 years ago

You're welcome :)

LogicalError commented 7 years ago

this version is available on the asset store, so I'm closing this ticket!