Problem with using Rect.set(), it does nothing.

When using Rect.set(), the rect does not change. I don’t know how else to better explain it. Here is the code, with unimportant parts removed.

   RectTransform DialogueBoxRect = new RectTransform();

    void Awake()
    {
        Player.DialogueBox = GameObject.Find("DialogueBox");

        if(Screen.width < 1280)
        {
            DialogueBoxRect.rect.Set(0, 14, Screen.width - 20, 300); // Dialogueboxrect HAS already been defined and set
        }
    }

It returns no errors, but it does absolutely nothing. It should be changing the dialogue box’s size to less than the screen, so that it can played in the gameview and be read, but it is still too big. Any help is appreciated, thanks in advance.

the problem is you’re changing the rect of DialogueBoxRect, which you are creating though the constructor which is not allowed and won’t do anything because this way it’s not even a part of a gameobject. I guess you should instead be doing something like

Player.DialogueBox.GetComponent<RectTransform>().rect.Set(...

try rt.sizeDelta = new Vector2(100, 100);