Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

I'm running on a Ryzen 5600X and CPU utilization is low with none of the cores maxed out - so it's clearly a bottleneck somewhere.  On further testing I've found that it only becomes unusable when working with prefabs.

If I drop a prefab into the scene and unpack it, I can have over 1000 characters and it's super laggy but doesn't lock up the editor.  If I leave it as a prefab every change takes 15-60 seconds (Unity pops up the "Hold on" window with STM's OnInspectorGUI and Unity's save scene and import assets taking the the longest).  Multiple changes also get queued (like dragging to select a color from the color palette), which can lock up unity for several minutes at a time.

I tried creating completely new prefabs to test this and got the exact same behavior - it's at least 20x slower when working with prefabs.  It doesn't matter if I'm working with a prefab in the scene or in prefab mode.

Huh okay that's interesting - not at all the issue I thought that was happening at all if there's a difference inside and outside of prefabs.


It could be something with a newer version of Unity forcing some editor code to be called more than it should (There shouldn't be a difference at all when editing the color value of a mesh inside and outside of a prefab), so will have to look into that for sure. I'm getting a few ideas already but will need to test them myself to see if they make a difference and don't break anything else. (Marking the textMesh variable as nonserialized is the first thing I'm going to try, but it should not be taking 15-60 seconds to save a 4k vert mesh on any CPU from the last decade regardless...?)

One guess I have that you can try is... is auto-save enabled in the prefab editor? Not sure if it would make a huge difference if it's somehow taking 15-60 seconds at any point, but that would force a save every time a value updates and force other instances to update too which could be a lot if done every single frame.

So will experiment with this soon! Sorry for the trouble.

(3 edits)

I tried turning off auto save and it doesn't really make a difference (it happens both in prefab mode and in scene mode when working with prefabs).  I made two more strange observations:

1.  The slowdown seems to heavily depend on the text content.  If I copy/paste "Hello World!" over and over it performs better and I can get about twice as many characters before it slows down to the same level as my tutorial text (which is ~900 characters).  The tutorial text is just plain English text, nothing fancy.

2.  With the repeated text prefab, If I save the prefab and then drop it into the scene I get the laggy, but still usable behavior; however, the moment I touch the actual text, it turns bold (in the inspector window) and starts locking up unity.

Note that when I say "usable", I mean I can edit the text settings. It's still pretty unusable for typing text into the text box.

EDIT:  I'm also noticing that after recompiling Unity takes over a minute to import any prefabs that have a STM object (but only if they're in the scene).  I also tried making the text mesh non-serialized and it made no difference.

Ok, update...


First, Is this the type of setup you're describing? I'm trying this in an old Unity version (My main development project for STM) so it could be something unique to a newer version, but I just want to see if I'm on the same page or not:



The bit of lag I see here seems typical for multiple prefabs getting edited, but from what you described you're seeing something a bit more than this, so is this type of setup correct, but just with a *lot* more text? Additionally, I tried this both inside and outside of Unity UI and didn't see a difference in UI text - if anything, the UI text had better performance than the above gif? So will try in Unity 6 soon.


Second, I went ahead and wrote the auto pagination script, but I don't actually see a visible performance boost on my end vs. just editing a normal text mesh, but I'm going to share it regardless:

https://pastebin.com/UReTwUEf

You just attach this as a component to an STM object and it sets up others like this:


There's an option to automatically grab the amount of lines from the text mesh, redo the layout if the amount of lines changes, and the amount of lines each STM object will render. It's useful, but I unfortunately don't think it'll be the answer to this problem just yet. Worth a shot, though.


So I will try it in Unity 6 soon, but I want to make sure I'm understanding the problem correctly as I'm not seeing any locking up on my end just yet? I feel like I must be missing something obvious, sorry I've been bouncing between so many different projects and I might be getting stuff mixed up.

I'm getting strange results when testing.  If I drop a prefab with a moderate amount of text into the scene, I get "normal" lag until I edit the text, at which point it starts locking up.  Then if I unpack the prefab, it's back to normal.  The more text I add to the prefab (beyond the amount initially there), the slower it gets.  I recorded a video demonstrating this - do you have a support email I can send it to?

The one consistent thing is:  whenever the text in the STM text box turns bold, it starts locking up unity.  When I edit the text as described above, it turns bold and this happens.  For my tutorial prefab, I notice it's already bold when I try to edit it, meaning everything is super slow right from the start (even just opening it in prefab mode).

As for the auto pagination script: I couldn't get it to work.  If I set it to auto it does nothing.  If I click manual setup, it creates one empty STM object.  I couldn't get it to overflow text into other objects no matter how much text I added.

Hm, so it's when you have a prefab, and then change the text in the scene to be different... When I do that from the state of the .gif above (clicking the the first object, editing text) The text does turn bold, but I'm not seeing any performance issues quite yet, so maybe it's a version thing...?


I did just find and fix another bug that could potentially cause a UI layout to rebuild far too often (or not often enough), so there's a slim chance *that* could be the cause, but I didn't apply it to my test project yet or anything, just another bug I fixed.



The autosplit script needs "STMPagination" in your project, which can be found in the sample scenes - I don't think the script would have compiled without it, but if it's creating just one empty object, it's either set to only create one with one setting or another, or an error is happening and it's stopping. Could I see your inspector? Mine looks like this:



It's really just meant for setting up STMPagination in a "page" format like this, the STMPagination script can be used on its own to have overflow text go to another STM component, like once the objects have been laid out, the script could be deleted. I wasn't able to reproduce an error when adding the component to an STM object on my end, but it's an editor script I just wrote, so I might not be accounting for every use-case quite yet.