snozbot / fungus

An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
MIT License
1.65k stars 292 forks source link

Default SayDialog will drop frames first time italic is called. #125

Closed unknowndevice closed 9 years ago

unknowndevice commented 9 years ago

I've noticed that the first time italics is called with the default SayDialog prefab it will lose frames on a build. I think this is happening because "Exo2-Regular" has no italics font packaged.

This error stops happening if you switch to "Amaranth-Regular" which has the italic font bundled.

chrisgregan commented 9 years ago

Ah I hadn't noticed that before, thanks for pointing it out. Any other ideas for a fix on this one? I guess we could swap it out for a different font that has an italic set included, would mean anyone upgrading to latest version of Fungus would need to set their font references again though. What about changing the Character font setting to Unicode instead of Dyamic - does that have the same problem?

movrajr commented 9 years ago

My standalone build has framedrop the first time the dialog is displayed in a 3D scene where the camera is rotating, even after replacing the italic "Exo2-Regular" with normal Arial. In the Editor playback is smooth even though the profiler indicates a 25 ms spike: 14 ms in Block.ExecuteBlock() and 10 ms in Canvas.SendWillRenderCanvases().

KumoKairo commented 9 years ago

This is some font caching stuff, I usually add a letter or two of every style on an invisible (alpha 0) text component at the start of the scene so it can pre-cache it when the scene is loading. It's smooth in the editor because it somehow retains cache between Plays

It may be not the most elegant way of doing it, but when I stumbled upon this problem myself, this is the only solution I've been able to find.

movrajr commented 9 years ago

@KumoKairo Thanks for that trick, going to try that. I'm not sure if the reason is specifically font caching or just the inefficiency of enabling Canvas objects in general. Because the hiccup now occurs when a second canvas with the default arial font is enabled. Whatever the cause, enabling Canvases on startup, making them alpha 0 and fading them in on demand could indeed be the way to go for now.

BTW Unity 5.2, now in beta, introduces UI performance improvements. I was unable to test Fungus in the beta, because Unity crashes when starting the scene. I have submitted a bug report yesterday which Unity QA was able to reproduce.

@chrisgregan Italic Exo 2 is included here: http://www.fontsquirrel.com/fonts/exo-2

movrajr commented 9 years ago

@KumoKairo Setting all Canvases to use a single font (using Arial for now) and fading in the first one makes my scene smooth, even when toggling the second Canvas. :+1:

movrajr commented 9 years ago

@KumoKairo I confirm your caching trick works too for a smooth scene with multiple fonts. Downside: there is a noticeable delay between launching the build and the scene starting. I'm going to play around with the font import settings.

chrisgregan commented 9 years ago

Thanks for the suggestions, gonna try out the 5.2 beta to see if it fixes this issue, if not I'll see if there's a way for Fungus to cache the fonts automatically.

movrajr commented 9 years ago

Forgot to tell the result of a test project for the 5.2 beta I made earlier today. Added a rotating camera, removed the Flowchart and made a script to enable a custom dialog Canvas by pressing the space bar. When I run the standalone build and press space the scene freezes shortly again. So unfortunately not much has changed in that regard.

@chrisgregan If you're going to check out 5.2 beta, maybe you can see why the editor crashes when there's a Fungus flowchart in the scene and give QA a heads-up. There have been some reports about the beta crashing on scene start in combination with some assets that may be related. For example: http://forum.unity3d.com/threads/constant-crashes-on-play.338596

chrisgregan commented 9 years ago

Hmmm, looks like I need Unity Pro to access Unity beta versions. :(

Can anyone provide more info on the issue with 5.2 beta? Error messages or screenshots would be very helpful.

Also I'm going to hold on implementing the workaround for this issue until we can check if it's already fixed in 5.2

movrajr commented 9 years ago

Last I tried the stuttering was still there in 5.2 beta. Maybe font caching is just something the user is expected to deal with. It's been that way for years: http://answers.unity3d.com/questions/149762/how-to-prepopulate-font-cache.html

As for the crash on playback, that's an issue many people have reported with other assets. Seems to be related to hidden gameobjects. http://forum.unity3d.com/threads/unity-5-2-beta-6-is-available.346422/

chrisgregan commented 9 years ago

If someone wants to write a Cache Font command I'd be happy to add it in to the library?

For the crash bug, it sounds like we're not doing anything wrong and it's a bug in Unity that they're working to fix. Let's see if it's sorted out in beta 7.

movrajr commented 9 years ago

Crash bug should be fixed in a future release http://issuetracker.unity3d.com/issues/fungus-flowchart-crashes-unity-5-dot-2

chrisgregan commented 9 years ago

Awesome - thanks for sending in the bug report!

chrisgregan commented 9 years ago

I've added the Cache Font command as a requested feature in Trello, and will close this issue.