I’m trying to update a text component multiple times in a single frame within a coroutine so that it will update it’s associated RectTransform. However, I can get the rect transform to update if my code contains a yield return null statement.
Here is my process for a single frame:
- Start the coroutine
- Instantiate a new object which has horizontal layout, content fitter, text, and recttransform components.
- In a for loop, I update/increase the text value of the text component in order to increase the width of the associated rect transform.
- After each iteration of the loop I check the sizeDelta.x of the rect transform to see how much the overall width of the rect transform has changed.
- End coroutine
At every iteration in the for loop, I check the width of the of the rect transform, hoping that it will have a larger width value (which it should because of the aforementioned horizontal layout and content fitter components). However, after each iteration, i read the rect transforms width value, and it’s always the same - the starting value at which it was instantiated.
I can get the rect transforms width to update if I include a yield return null at the end of the loop, but I would prefer to not have to do this as it means that I have to wait frames in order to continually update the rect transforms width.
Am I overlooking something? Is it possible to update a rect transforms width multiple times in a single frame?