- Home /
Prefab running once as planned, crashing Unity on second run
I'm trying to instantiate a user-controlled avatar (in this case a simple cube from a prefab).
There must be something wrong with the way my prefab is set up, because my program is working as intended when I drop the necessary scripts onto an existing GameObject cube.
When I run my program once, it works fine with all the scripts triggering as they should. I stop and run again and Unity crashes to desktop.
Here's the code that I think is suspect. Being a novice C# and Unity user, I wouldn't be surprised if I'm doing it wrong, so any help is greatly appreciated.
Thanks in advance.
public class InstantiatePlayer : MonoBehaviour {
public new Transform PlayerBlock;
void Start () { //place movement and behavior scripts onto transform PlayerBlock.gameObject.AddComponent("PlayerMove"); PlayerBlock.gameObject.AddComponent("ColorChangeBehavior"); //put a new moveable cube with behavior script on it at origin point Instantiate(PlayerBlock, new Vector3(0.0f,0.0f,0.0f), Quaternion.identity); }
}
Did you file a bug report? Attach your script and explain how it can be reproduced and you'll get a reply shortly.
Ya, like said above, file a report. There is nothing wrong with your code so a bug report is all that can be done. On the bright side, nothing is wrong with your code :D.
Answer by vivek2012.du · Jul 13, 2011 at 10:17 AM
Use Prefab in your Game Here is the tutorial for that . http://lnkd.in/J6ufVr . Here is demo and code for Prefab instantiate so download and try to undestand i hope u will get the solution ..
Your answer
![](https://koobas.hobune.stream/wayback/20220612203226im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Prefab and certain script makes unity crash. 1 Answer
Unity Crashes When Spawning Prefab 2 Answers
Crash from texture memory? 2 Answers