# Rect transform stretch of a child object is set to 0 after instantiation

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:

Children Popup and ScreenDim look like this:

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.

• Please include the code you are using to instantiate the prefabs in your question. Feb 1 at 20:51
• 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. Feb 2 at 13:33

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);
}