Posts: 1,969
Threads: 81
Joined: Jun 2017
08-12-2020, 12:42 AM
(This post was last modified: 08-12-2020, 12:43 AM by _Aka_.)
Hi,
Here is a Unity forum thread about that issue:
https://forum.unity.com/threads/loading-updatepreloading-taking-up-precious-time-for-no-reason.252578/
It's a long thread, but it seems that it's a long running issue that can be avoided by commenting calls to Resources.UnloadUnusedAssets().
Also, someone said that it might happen only in the editor, but I would advise you to make sure of that yourself by profiling a build.
Let me know if that solved the issue.
Have a nice day
Please consider leaving a
review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 12
Threads: 2
Joined: May 2019
ok. im still not sure whats calling that Resources.UnloadUnusedAssets()
Posts: 1,969
Threads: 81
Joined: Jun 2017
Curvy Splines has a couple of those calls, but it can also come from other parts of your project. You can easily find out by doing a research on all files (CTRL+SHIFT+F on most code editors) of the string "Resources.UnloadUnusedAssets()"
Please consider leaving a
review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 12
Threads: 2
Joined: May 2019
thanks. i found one call from curvy: \Assets\Plugins\Curvy\Base\CG Modules\CreateMesh.cs at line 523. i commented that out and lag spike is gone
i hope that modification does not make any problems to my project
Posts: 1,969
Threads: 81
Joined: Jun 2017
As you can read here:
https://docs.unity3d.com/ScriptReference/Resources.html
"Some loaded assets, most notably textures, can use up memory even when no instance exists in the Scene. To reclaim this memory when the asset is no longer needed, you can use Resources.UnloadUnusedAssets."
This is related to only assets loaded via the Resources class, and not ones assigned through the inspector.
Assets loaded by Curvy Splines via the Resources.Load method are not numerous. It loads the CurvyDefaultMaterial material, and the icons for the UI. That's it. So Resources.UnloadUnusedAssets does not do much, since the icons for the UI are referenced for the life time of the Unity session, only CurvyDefaultMaterial is unloaded if not used anymore.
To sum up, I don't believe that commenting that line would be an issue. If it happens to be, please let me know.
Also, do you have a huge number of assets? This is the only explanation I find for Resources.UnloadUnusedAssets to take so much time.
Please consider leaving a
review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 12
Threads: 2
Joined: May 2019
thanks. this is new informantion for me. i have many assets in my game. it feels like i should call "Resources.UnloadUnusedAssets()" in save and loadgame.. or anywhere where i can put some kind of loading screen
Posts: 1,969
Threads: 81
Joined: Jun 2017
Maybe it's a good idea. I don't have enough experience using that method to say for sure. Just make sure it is worth it by profiling what's happening cpu and memory wise.
Please consider leaving a
review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 12
Threads: 2
Joined: May 2019
hi again. how do i destroy the road safely? i used to do this by manually destroying child of "Create Mesh" which is named "Create Mesh_5_Mesh000" which is holding the mesh, but i got somekind of pooling errors from it. i guess that is not the right way
Posts: 1,969
Threads: 81
Joined: Jun 2017
Could you send me the error message, and if possible a reproduction case?
As far as I know, and in my tests, calling Destroy(yourMeshGameObject) works. You could also call yourCreateMeshModule.Clear()
Let me know if that works for you.
Please consider leaving a
review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 12
Threads: 2
Joined: May 2019
in my case sometimes i want to destroy road before i save it to scene. CreateMesh.Clear() is working fine. no errors
here is the error that popped up sometimes when i deleted the road under Create Mesh object:
InvalidOperationException: [Curvy] Could not create managed resource of type 'Mesh'. In some cases this is due to not enough elements in a resources Pool
FluffyUnderware.Curvy.Generator.CGModule.AddManagedResource (System.String resourceName, System.String context, System.Int32 index) (at Assets/Plugins/Curvy/Base/CG/CGModule.cs:609)
FluffyUnderware.Curvy.Generator.Modules.CreateMesh.getNewMesh () (at Assets/Plugins/Curvy/Base/CG Modules/CreateMesh.cs:819)
FluffyUnderware.Curvy.Generator.Modules.CreateMesh.writeVMeshToMesh (FluffyUnderware.Curvy.Generator.CGVMesh& vmesh) (at Assets/Plugins/Curvy/Base/CG Modules/CreateMesh.cs:762)
FluffyUnderware.Curvy.Generator.Modules.CreateMesh.createMeshes (System.Collections.Generic.List`1[FluffyUnderware.Curvy.Generator.CGVMesh]& vMeshes, System.Boolean combine) (at Assets/Plugins/Curvy/Base/CG Modules/CreateMesh.cs:678)
FluffyUnderware.Curvy.Generator.Modules.CreateMesh.Refresh () (at Assets/Plugins/Curvy/Base/CG Modules/CreateMesh.cs:565)
FluffyUnderware.Curvy.Generator.CGModule.doRefresh () (at Assets/Plugins/Curvy/Base/CG/CGModule.cs:833)
FluffyUnderware.Curvy.Generator.CurvyGenerator.Refresh (System.Boolean forceUpdate) (at Assets/Plugins/Curvy/Base/CG/CurvyGenerator.cs:600)
FluffyUnderware.Curvy.Generator.CurvyGenerator.TryAutoRefresh () (at Assets/Plugins/Curvy/Base/CG/CurvyGenerator.cs:627)
FluffyUnderware.Curvy.Generator.CurvyGenerator.Update () (at Assets/Plugins/Curvy/Base/CG/CurvyGenerator.cs:265)