I’ve a guardian gameobject (Empty
) with a content material measurement fitter with horizontal and vertical match set to most well-liked measurement which can be a Horizontal Layout Group
with Control Child measurement
width and peak enabled:
It has received a TextMeshPro
textual content as youngster, and now, because the textual content expands the guardian additionally expands. The downside is, I wish to get the peak of this guardian. And if I take advantage of this:
var rect = guardian.gameObject.GetComponent<RectTransform>.rect
Debug.Log($"Width: {rect.width}, peak: {rect.peak}");
and even,
var mValue = guardian.gameObject.GetComponent<RectTransform>.sizeDelta;
Debug.Log($"sizeDeltax: {mValue.x}, sizeDeltaY: {mValue.y}");
they each give 0.
I require some approach to extract the expanded width and peak. How can I try this?
NOTE: The content material of the kid i.e. textual content is being assigned dynamically, additionally the guardian/textual content is a prefab being instantiated dynamically i.e. through Instantiate
, and this isn’t finished within the begin methodology.
Okay, this is extra element concerning the hierarchy and stuff:
The hierarchy
So, ultimately chat bubbles are imagined to stack on high of each other, they get parented to ChatPanel, and every youngster is a prefab instantiated as talked about above, the prefab element are:
Textual contentItem (Note the MessageTextItem is principally not used, it is there for some previous code causes)
When I ship message, I log the width and peak of the white a part of the chat bubble which is principally the **chatTextBubble above, utilizing the code: **
var expRect = chatTextBubble.GetComponent<RectTransform>();
Debug.Log($"dvz:: expRect width is: {expRect.rect.width} and peak is: {expRect.rect.peak}");
and it logs 0. Please inform me what am I doing improper. It seems to be just like under instance however, not working.
This is what it seems to be like throughout gameplay:
EDIT:
I simply observed, the chatTextBubble has this throughout gameplay:
however, logs 0 after I log with the above talked about code.