- Home /
Instantiate prefabs working in editor but not in builds
Hi,
I'm having some problems instantiating prefabs in my builds. Everything works fine in the editor. You can see ad demo of my game here: https://www.youtube.com/watch?v=vY8CNVwnPxY Notice the blood and the dead rats. The blood is a particle fountain. The dead rat (DeadReplacement in code) is a simple animated mesh. Now take a look here: http://dl.dropboxusercontent.com/u/31530787/UnityBuilds/Maze/Maze.html No blood, no dead rats. So the web build isn't instantiating these prefabs. Same for .exe or Android builds. Other prefabs like the enemies, the ammo pickups etc. are being instantiated correctly.
Here is my code for the instantiating of the dead replacement rats (in the rat health script):
public void Die()
{
//Debug.Log(myTransform.name + " dies");
if (DeadReplacement && GameObject.FindWithTag("Player")) //player could be killed in the mean time
{
Transform newDeadReplacement = (Transform)GameObject.Instantiate(DeadReplacement, myTransform.position, Quaternion.identity);
if (newDeadReplacement.rigidbody) //does the dead replacement need a push away?
{
Vector3 dirAway;
if (ExplosionPosition != Vector3.zero)
{
dirAway = (myTransform.position - ExplosionPosition).normalized; //this only works when being fired, when explosion it also pushes away from player
}
else
{
dirAway = (myTransform.position - GameObject.FindWithTag("Player").transform.position).normalized; //this only works when being fired, when explosion it also pushes away from player
}
dirAway += new Vector3(0, 0.1f, 0);
newDeadReplacement.rigidbody.AddForce(dirAway * forceAwayMultiplier);
}
}
Destroy(gameObject);
}
Here is my code for the blood:
//some blood
if (BloodFountain)
{
Instantiate(BloodFountain, myTransform.position, Quaternion.identity);
}
You can see I'm trying different approaches. Nothing works in the builds.
Here is my code for instantiating an enemy: private void SpawnEnemy(Transform EnemyToSpawn, Vector3 PositionToSpawnFrom) { Transform newEnemy = (Transform)Instantiate(EnemyToSpawn, PositionToSpawnFrom, myTransform.rotation); newEnemy.parent = myTransform; }
This spawning of enemies works in both editor as wel as all the builds (web, exe, Android). Why does this one work, but the dead rat doesn't?
I also tried lowering the quality settings for the builds, but that didn't make any difference either.
Why are some prefabs being instantiated correctly, while other aren't (in the builds). What am I missing or doing wrong? Any thoughts on this?
Thank you for reading this.
Boi
I am also having same problem and trying to find out reason with no luck.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
After Build, instantiate does not work 1 Answer
[Android]Minimum platform required error 1 Answer
Plant Reproduction, Instantiate problem 1 Answer
How prefab the instance works? 1 Answer