Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Boi · Dec 17, 2013 at 09:43 PM · instantiatebuildprefabs

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rocky777k · Dec 27, 2015 at 09:27 AM 0
Share

I am also having same problem and trying to find out reason with no luck.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges