YarnSpinner-Unity icon indicating copy to clipboard operation
YarnSpinner-Unity copied to clipboard

Entering Play Mode randomly takes longer to load sometimes

Open KXI-System opened this issue 2 years ago • 3 comments

(This is a post documenting findings of this issue on Discord)

There is this elusive bug where some users are finding increased loading times when entering Play Mode sometimes. The increased load times appear inconsistently, and seemingly appears after some time before then resolving itself. Users who have added in the Sample files have found that removing them decreases the load times for a while, but then the load times increase again after a while.

On Discord, 2 users confirmed to have the same issue. Both have the "Enter Play Mode" option enabled as well.


Discord Logs:

@/Magna on Discord

Unity version: Unity (2021.3.0f1) I have this problem where sometimes it takes a lot to load, from 1 min to 2, I'm not using Yarn spinner yet in the project, only have it installed unknown Packages in project unknown

Btw Idk about versus but I have this enabled unknown

link to message

@/versus_ on Discord

(Sorry to be meddling in your conversation, but I do have the samples imported since my very first tests to get to know Yarn and it is still from time to time taking over 3 minutes)

[in response to removing example files] I am still getting slightly slow times, but in any case nowhere near the 3 and a half minutes I have been getting

Sorry to be a bummer, but it happenned again, even after removing the Samples This time I did absolutely nothing, just Alt+Tabbed to the web browser to check the FMod API, went back to Unity and hit Play

link to message

KXI-System avatar Jul 17 '22 01:07 KXI-System

We are having a similar issue in our project. At first we tried it in a small demo project and everything worked fine. But when we migrated to our real project (which is not the biggest but still big) we started seeing long loading to get into play mode.

After some investigating I figured it was coming from the YarnPreventPlayMode class that would look for any yarn errors and "prevent play mode" if there was any. But in order to get that information it uses GetAllAssetsOf() which uses AssetDatabase.FindAssets.

AssetDatabase.FindAssets works on the whole project, but because it's all indexed it works pretty fast. When we're looking for only the YarnProject it's fine because it only returns YarnProjects which you shouldn't have too many of. But the type for .yarn files is TextAsset which is the same type as EVERY C# script in your project.

And suddenly you're sorting through thousands of files multiple times right before starting playmode. There has to be a better way.

For our project I've limited the search to a specific folder without any C# scripts in it, which decreases load time considerably. That's just a quick patch, do you have any plans for a better/long-term solution ?

Garazbolg avatar Aug 01 '22 16:08 Garazbolg

I have encountered this issue constantly.

One of the things I did is disable Search All Assemblies in my YarnProject, as it becomes slow when it is compiling a large project. However the problem persists with YarnPreventPlayMode.

Cdddo avatar Aug 08 '22 23:08 Cdddo

Try closing all un-needed unity windows. Some of them can take a while, like the Package Manager tab.

Bryan-Legend avatar Sep 02 '22 00:09 Bryan-Legend

Also have this problem, it's not a major issue although obviously annoying. Happy to try and look out for or test potential causes to narrow it down.

loosegrid avatar Nov 21 '22 15:11 loosegrid

We have the issue on a very large project and it delay the play mode launch more than a minute for some of our developpers. Is there any workaround ?

Greewi avatar Dec 08 '22 14:12 Greewi

Try using this tool to get a call stack on what is taking so long: https://forum.unity.com/threads/introducing-the-editor-iteration-profiler.908390/

Bryan-Legend avatar Dec 08 '22 15:12 Bryan-Legend

Eventually like Garazbolg suggested I fixed this problem by changing YarnEditorUtility.cs to filter the query in line 226 to search only in specific folders instead of the whole unity assets database, which in my project is pretty large (therefore slow), e.g.:

=> AssetDatabase.FindAssets(filterQuery, new[] { "Assets/_PROJECT/Dialogue" })

It would be better to have the ability to configure an array of folders in the YarnProject inspector... or have another solution.

Cdddo avatar Feb 15 '23 02:02 Cdddo

We also experience this issue. I think enforcing no file errors when playing in this way is a bad idea, seeing as for large projects it takes way too long to process.

Ideally this is optimized, allow the functionality to be disabled, or these errors are processed at another time (import, runtime load).

rob5300 avatar Feb 27 '23 17:02 rob5300

Was just profiling my code because entering Playmode takes longer and longer and found out that 2sec of it is designated to this YarnSpinner check. This quickly adds up over time. I will manually copy in the YarnSpinner project, so I can make the adjustment that @Cdddo mentioned, but I'd be great to have a configuration of some kind.

leohilbert avatar Mar 08 '23 14:03 leohilbert

We believe that this is now fixed as of the upcoming v2.3 release. I'll close this issue here; because the underlying code has changed quite a bit, we'll consider any reoccurrence of behaviour like this to be a new issue.

Thanks to everyone for contributing diagnostics that helped track down this problem!

desplesda avatar Jul 04 '23 02:07 desplesda