Why does Unity stop responding on pressing Play?
Hello!
I've encountered a problem with Unity and found no solutions.
Last night, when I pressed Play to see if an image gets instantiated or not, Unity stopped responding... It happened several times this morning too, and I don't know why.
I noticed though that it only happens if the prefab I want to instantiate is located in Resources folder. I tried it with an image and with a game object and it does the same. If I move the prefab to Resources\Prefabs folder, then it doesn't stop responding, but I get an error:
ArgumentException: The Object you want to instantiate is null. UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:383) UnityEngine.Object.Instantiate (UnityEngine.Object original) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:240) LoadScript.OnLoad () (at Assets/Scripts/LoadScript.cs:49) LoadScript () (at Assets/Scripts/LoadScript.cs:35)
This is the code I use to try to create 12 instances of the game object:
public class LoadScript : MonoBehaviour{
GameObject gameObject;
int instances;
public GameObject panelToAttachObjectsTo;
void Start(){
instances = 12;
OnLoad(); }
public void OnLoad(){
while (true) {
for (int p = 0; p < instances; p++) {
gameObject = (GameObject)Instantiate(Resources.Load("GOField")) as GameObject;
gameObject.transform.parent = panelToAttachObjectsTo.transform;
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612230813im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
unity assets folder is empty 2 Answers
Edit a script from another script 1 Answer
Unity Editor Slows Down, It's Lagging, & Problem navigating in Unity Editor 0 Answers
unity app with android studio 0 Answers
Unity 2017.4 has no package manager 2 Answers