0
\$\begingroup\$

I have the following hierarchy of my prefab:

-PopupParent
--Popup
---ScreenDim

They all have Rect Transform set to Stretch. Anchor mins are set to 0 and Anchor maxes to 1. Left, top, right and bottom are set to 0. When I pull this prefab to a Canvas manually, all works as expected.

When I instantiate the prefab the problem I am encountering is, that the PopupParent is stretched as expected, to the full screen, but all its children are not.

PopupParent looks like this: enter image description here

Children Popup and ScreenDim look like this: enter image description here

The instantiation I am doing using the Spawn Prefab Node in the Event editor provided by the ORK Framework. I am Mounting the PopupParent to my UICanvas.

It could be, that the issue is caused by some Framework settings, but it might very well be related to how Unity works in general. I am not sure and can't find a way to figure it out.

SOLUTION: I got ORK support to reply and solve the issue for me: http://forum.orkframework.com/discussion/6465/spawning-a-prefab-with-a-stretch-property#latest

TL;DR: Regular mounting and UI mounting works slightly different.

\$\endgroup\$
2
  • \$\begingroup\$ Please include the code you are using to instantiate the prefabs in your question. \$\endgroup\$
    – Kevin
    Commented Feb 1, 2021 at 20:51
  • 1
    \$\begingroup\$ When you solved your question, please post an own answer describing the solution and accept it. That way others can learn from your and the question appears as answered in the question list. \$\endgroup\$
    – Philipp
    Commented Feb 2, 2021 at 13:33

1 Answer 1

2
\$\begingroup\$

I got ORK support to reply and solve the issue for me: http://forum.orkframework.com/discussion/6465/spawning-a-prefab-with-a-stretch-property#latest

TL;DR: Regular mounting and UI mounting works slightly different.

This is the code that I got together to make the mounting (and stretching) work properly:

public string GVKey_ORKUICanvasTag = "UICanvasTag";
private string UICanvasTag;
private GameObject UICanvas;
// Start is called before the first frame update
void Start()
{
    UICanvasTag =  ORK.Game.Variables.GetString(GVKey_ORKUICanvasTag);
    UICanvas = GameObject.FindGameObjectWithTag(UICanvasTag);
    resetTransformOffset();
    SetParent(UICanvas);
}

private void resetTransformOffset()
{
    RectTransform rectTransform = GetComponent<RectTransform>();
    rectTransform.offsetMin = new Vector2(0,0);
    rectTransform.offsetMax = new Vector2(0, 0);
}

private void SetParent(GameObject parent)
{
    transform.SetParent(parent.transform, false);
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .