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
0
Question by MibZ · Sep 27, 2012 at 08:33 PM · instantiateprefabvelocity

Runtime prefab instantiation issue

Update: I've been trying to figure this out for a few hours today, and I've discovered that if I create a new Spawner & Branch from the prefabs and press Play the velocity calculation doesn't work, but if I save and reload Unity the new Branch's velocity calculation works just fine but the instantiated ones continue to be broken.

After debugging the crap out of this and talking to another programmer on the project, I'm fairly certain it is an under the hood problem with some kind of memory allocation glitch.

I'm going to rewrite the scripts for the throwable objects and the respawner and if that fixes the problem I'll update this again.

Original Post: So as my project stands at the moment I have tree branches that the player can detach and throw, and empty objects that "regrow" the object after it is removed.

Before the branches are pulled off the tree, they are childed to the respawner. When they're detached, they're "un-childed" and after a set amount of time the respawner instantiates a new instance of the prefab.

If I set up a respawner and childed branch in the editor I can play the game, rip it off, throw it, and the respawner will spawn a new one.

BUT the problem is that once the new branch is thrown the velocity calculation no longer works, so as soon as it is let go it just falls straight to the ground. My velocity is calculated/applied with this code...

 velocity = (gameObject.transform.position - prevPos) / Time.time;
 gameObject.rigidbody.velocity = velocity * velocityMagnitude;   //Apply velocity

.

It looks like everything I'm trying to do is working, but I can't find the problem and I suspect it may be this line of code.

 myBranch = (GameObject)Instantiate(branchToGrow);

Can I not instantiate the new instance and store a reference to it on the same line?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MibZ · Sep 28, 2012 at 06:59 PM

In case someone with a similar problem actually searches before asking a new question, in the process of rewriting my scripts (They needed to be rewritten anyway, I wanted them to be more modular) I figured out that my problem was that the settings needed for the script to work were set up in the Start function, I changed that to Awake and my problem was solved.

Comment
Add comment · Share
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

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

9 People are following this question.

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

Related Questions

Instantiating a prefab with velocity 1 Answer

initial velocity for instantiated ragdoll prefab 1 Answer

How to instantiate a prefab with initial velocity? 2 Answers

instantiating vertically 2 Answers

How to Add Y Axis Offset to transform.localPosition on an Instantiated Prefab? 2 Answers


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