In Unity I created a Panel with 3 children (An UI Image (LogoAch), and 2 TextMeshPro components (Name, Progress)).
It looks something like down below:
I saved this as a prefab and I try to instantiate it through code. Problem is for whatever reason the UI Image is not ?rendered? in the instantiated version? I have this short video showcasing the problem:
https://www.youtube.com/watch?v=RTa_noJy4bE
Does anyone have any hunch of what exactly is the problem?
My code is the following:
// instantiate the popup
GameObject achPopup = Instantiate(prefabAchievementsPopup, transform.position, transform.rotation);
// set it as a child of Canvas
achPopup.transform.SetParent(canvas.transform);
// set Pos Z to 0
// set Left, Bottom to 0, 300
// set Right, Top to 0, -300
// set Scale to (1,1,1)
achPopup.GetComponent<RectTransform>().localPosition = new Vector3(1000, 1000, 0);
achPopup.GetComponent<RectTransform>().offsetMin = new Vector2(0, 300); //left, bottom
achPopup.GetComponent<RectTransform>().offsetMax = new Vector2(0, 300); //right, top
achPopup.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
// set new sprite in Logo, new text in Name, Progress
achPopup.transform.Find("LogoAch").GetComponent<Image>().sprite = circleOfLifeLogo; // [SerializeField] private Sprite circleOfLifeLogo;
achPopup.transform.Find("LogoAch").GetComponent<Image>().color = circleOfLifeLogoColor; // [SerializeField] private Color circleOfLifeLogoColor;
achPopup.transform.Find("Name").GetComponent<TMPro.TextMeshProUGUI>().text = "Circle of life";
achPopup.transform.Find("Progress").GetComponent<TMPro.TextMeshProUGUI>().text = "1/1";

