- Home /
cachedTextGenerator not working with instantiated canvas
Hello,
Here is my problem: I need to use the cachedTextGenerator of a text inside a canvas to know its number of lines.
When I place a canvas in the scene, it works fine and I'm able to get the number of lines (using Canvas.ForceUpdateCanvases) from the cachedTextGenerator of the text.
But when i instantiate the canvas from a prefab, the cachedTextGenerator seems to give wrong informations. The string is correctly displayed on the canvas, but the cachedTextGenerator.lineCount always returns 0 (as well as the characterCount or any other thing in the cachedTextGenerator).
I'm probably missing something, does someone have an idea? Thank you in advance.
Answer by andreimarks · Aug 10, 2015 at 01:32 PM
You've probably resolved/moved on from this problem, so this is for later readers. I had the same issue, and it looks like cachedTextGenerator won't return the proper information until the next frame.
Getting it next frame was good enough for my purposes, but if there's a way to get all the info in the same frame, I'd love to know!
That really helped, but in my case wait to second frame didn't work. I realized that cachedTextGenerator sometimes updates even in 2-3 frames after text change.