Tuesday, April 16, 2024
HomeSample Page

Sample Page Title


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:

enter image description here

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

enter image description here

Parent:
enter image description here

Interface
enter image description here

MessageField
enter image description here

OutputSection
enter image description here

Viewport
enter image description here

ChatPanel
enter image description here

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:

hierarchy
enter image description here

stackItem
enter image description here

ItemParent
enter image description here

Tag
enter image description here

Textual contentItem (Note the MessageTextItem is principally not used, it is there for some previous code causes)
enter image description here

ChatTextBubble
enter image description here

enter image description here
These are expanded under:
enter image description here
enter image description here

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: enter image description here

EDIT:
I simply observed, the chatTextBubble has this throughout gameplay:

enter image description here
however, logs 0 after I log with the above talked about code.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments