1
votes

I'm instantiating a prefab panel in unity and i'm settings it's parent to another panel like this :

GameObject notificationPanel = (GameObject) Resources.Load("NotificationWindow");
Text notificationText = notificationPanel.GetComponentInChildren<Text>();
if (notificationType == NotificationType.Warning)
{
    notificationText.color = Color.red;
}
notificationText.text = text;
GameObject newNotificationWindow =
(GameObject) Instantiate(notificationPanel, new Vector3(0, 0, 0), Quaternion.identity);   
newNotificationWindow.transform.SetParent(Settings.NotificationHolder.transform);

However when instantiated it's with an insane size, the parent panel has a layout group with a fixed size of the cell's inside of it why isn't this affecting it ? The new panel is around 10 times bigger than my screen. In the hierarchy view the new panel appears as a child correctly under it's parent. Also the 'z' position is around - 3900 why ?

1
Is your prefab correct? Also, is your newNotification's parent being set correctly?Cabrra
Did you fully read my question @Cabrra ? Yes they are both correct.PetqImaQkaputka

1 Answers

1
votes

So After reading the Unity Documentation: Instantiating the UI element all you have to do is to call:

newNotificationWindow.transform.SetParent(Settings.NotificationHolder.transform, false);

The "false"represents worldPositionStays parameter and this scales the UI.

Let me know if this works for you.