- Home /
Question by
acachitoro · May 18, 2020 at 06:02 AM ·
instantiateprefabdelegate
Instantiate not working as expected in delegate function
Hello, I'm using unity 2019.3.12f1 and I have the following code
public GameObject InstantiatePlayer()
{
Debug.Log("Yes");
GameObject go = Instantiate(playerPref, Vector3.zero, Quaternion.identity) as GameObject;
Debug.Log("Exist: " + go != null);
return go;
}
This function is called from a delegate function, but is not working as expected. But if instead if I call this function inside the start function this spawn the prefab as expected. How can I instantiate a prefab from a delegate function?
If I call the function from a delegate function, this will print only "Yes" on the unity console, getting stuck on the Instantiate part, and will not print the Exist... in console. But if this function is called from the Start function this will work as expected.
The weird part is that is when i build the game, this code is executed correctly and it spawns the prefab
Many thanks
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612234410im_/https://answers.unity.com/themes/thub/images/avi.jpg)