- Home /
RegisterDirtyLayoutCallback not working inside a vertical layout group
Hi all,
I have a script I'm adding to objects which also contain Text components. My script is meant to run a function whenever the Text's layout updates. All I've done to get that working is add a call back via the RegisterDirtyLayoutCallback function.
This works fine for most of my game objects however there are some where the call back never gets called. At first I thought it was something to do with those objects being instantiated from prefabs (I originally asked the question about that but have updated it since), however I've narrowed it down to the fact that the objects where the call back doesn't work are in a vertical layout group.
I can understand why the vertical layout group might also be using the call back but surely it shouldn't stop me from using it too? Does anyone know how I can get around this?
Interestingly if I register the call back and then on the next line of code do something to change the layout (set the font size for example), the call back does get called - it stops getting called later, presumably once the vertical layout group starts up.
Here's what the code looks like:
void Start()
{
m_text = GetComponent<Text>();
m_text.resizeTextForBestFit = false;
m_text.horizontalOverflow = HorizontalWrapMode.Wrap;
m_text.verticalOverflow = VerticalWrapMode.Overflow;
m_text.resizeTextMinSize = 1;
m_text.RegisterDirtyLayoutCallback(MyFunction);
}
private void MyFuntion()
{
// Do Stuff
}