I'm trying to place one in our field right below another, all ui belonging to an overlay canvas. I tried doing a few different ways subtracting height from different position types including rect types but the result of position I get seems to be inconsistent and a bit off. Thanks in advance.
Note the anchor pivot point for my body fields on Y is 1, because
I need it that way for the field to expand downwards as the field text grows in length.
So as you can see as the lines get longer and the height increases, the placement of the empty body fields is no longer accurate and gets thrown off. What's going on?
So here's the code I'm running to create my new Input fields, the current one turns white and "cements" itself as a new one empty non white one gets instantiated right underneath it, when you double click anywhere on the screen. Hence the times click on the code. Anyways the commented out code are all the different ways I've tried doing this but with no luck. The moment by input field height starts changing when there is more than one line, the new instantiated field doesn't get place properly, right underneath it like it does with just one line as you'll see in the images, below the code.
public void CementSegment_And_AddNewEmpty()
{
TimesClicked++;
StartTimesClickedTimer = true;
if (TimesClicked >= 2)
{
//Turns current segment to white (cements it)
NoteBodyObjects[NoteBodyObjects.Count - 1].GetComponent<Image>().color = new Vector4(1, 1, 1, 1);
//Adds new unsegmented/non white body to bottom of the (newly cemented white segment from code line above)
//float height = NoteBodyObjects[NoteBodyObjects.Count - 1].GetComponent<RectTransform>().rect.height;
float height = NoteBodyObjects[NoteBodyObjects.Count - 1].GetComponent<RectTransform>().sizeDelta.y;
//Vector3 pos = NoteBodyObjects[NoteBodyObjects.Count - 1].transform.position;
//Vector3 pos = NoteBodyObjects[NoteBodyObjects.Count - 1].GetComponent<RectTransform>().anchoredPosition;
//Vector3 pos = NoteBodyObjects[NoteBodyObjects.Count - 1].GetComponent<RectTransform>().localPosition;
Vector3 pos = NoteBodyObjects[NoteBodyObjects.Count - 1].GetComponent<RectTransform>().position;
Vector3 BodyFieldLocation = pos - new Vector3(0, (height * 0.5f), 0);
GameObject NewBodyField = Instantiate(DefaultBodyField, ContentParent);
//NewBodyField.transform.position = BodyFieldLocation;
//NewBodyField.GetComponent<RectTransform>().anchoredPosition = BodyFieldLocation;
//NewBodyField.GetComponent<RectTransform>().localPosition = BodyFieldLocation;
NewBodyField.GetComponent<RectTransform>().position = BodyFieldLocation;
NoteBodyObjects.Add(NewBodyField);
}
}