Here is the situation, In my project everything works fine. After I build the game for windows, the prefab does not instantiate. I don't know which part I missed.

This is how I load the prefab from Resources folder

private void Awake()
    areaButtonPrefab = Resources.Load<GameObject>("Prefabs/AreaButton1");

And this is how I instantiate prefab for each data in a List

public void SetAreaToUI()
    foreach (var j in areaList)
        cloneItem = Instantiate(areaButtonPrefab, originalRect.position, new Quaternion(0, 0, 0, 0), rect);
        TMP_Text text = cloneItem.GetComponentInChildren<TMP_Text>();
        AreaButtonData buttData = cloneItem.GetComponent<AreaButtonData>();
        buttData.area = j;
        text.text = j.areaName;
  • 1
    \$\begingroup\$ We'll need more information to be able to reproduce this problem. What calls SetAreaToUI, and when? What is areaList and how is it populated? etc. Try to edit your question to include a Minimal Complete Verifiable Example: all the code and scene setup steps we'd need to reproduce the problem in a new, empty project. Once we have that, we can test potential fixes to be sure they'll work for you. \$\endgroup\$ – DMGregory Dec 20 '20 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.