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 JayFitz91 · Sep 17, 2014 at 12:41 PM · rigidbodyinstantiatebuttonassign

Issue instantiating an object with button click

I want to fire a missile when I press on a button but the editor tells me the object has not been assigned when I'm sure it has been, the code I'm trying to use to instantiate is as follows:

 public void fireMissile()
     {
         GUICounters.missiles--;
 
     Rigidbody clone;
     clone = Instantiate(missile, shootPoint.transform.position, shootPoint.transform.rotation) as Rigidbody;
     clone.velocity = transform.TransformDirection(Vector3.forward * 200);
 
     if (clone.gameObject.tag == "missile")
     {
         Destroy(clone.gameObject, 1.5f);
     }
 }

And this is the Inspector for my object:

alt text

As you can see, the bullet has been added and it is a rigidbody, yet when I click the button, I get the error that it has not been assigned, if anyone could help I'd appreciate it as it is driving me mad.

capture.png (21.9 kB)
Comment
Add comment · Show 3
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 Adamcbrz · Sep 17, 2014 at 01:16 PM 0
Share

Is player$$anonymous$$issile linked to a prefab in the project and not a gameobject int the heirarchy?

avatar image JayFitz91 · Sep 17, 2014 at 02:10 PM 0
Share

Yeah its a prefab in the project tab, its not initially in the scene

avatar image t-shrai · Jun 29, 2016 at 09:27 AM 0
Share

Hey $$anonymous$$Fitz91, did your problem get solved? If yes, then can you please explain it to me as I'm facing the same problem, while doing the same thing that you were trying to do.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by spunktrumpet · Sep 17, 2014 at 02:04 PM

I'm assuming the missle is a prefab, put it into a folder with the name "Resources" and change "missle" to whatever your prefab is called.

 clone = Instantiate(Resources.Load("missle"), shootPoint.transform.position, shootPoint.transform.rotation) as Rigidbody;
Comment
Add comment · Show 1 · 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
avatar image JayFitz91 · Sep 17, 2014 at 03:16 PM 0
Share

Same issue unfortunately :/

avatar image
0

Answer by Eudaimonium · Jun 29, 2016 at 04:49 PM

Why are you instantiating it as Rigidbody?

Instantiate as GameObject, then access rigidbody later.

At which line is the exception thrown? I am not 100% sure but if you only instantiate as rigidbody, it will not have it's .gameObject which you are trying to access in the if tag comparison.

Comment
Add comment · Show 1 · 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
avatar image t-shrai · Jun 29, 2016 at 04:57 PM 0
Share

Yeah, I guessed the same thing later on. It was solved after instantiating as a Rigidbody.

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

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Projectile not moving properly in top down 2d shooter 2 Answers

The variable othertransform of Prefab has not been assigned 2 Answers

Multiplying something.forward using a variable doesn't actually multiply, but multiplying by a number does. 1 Answer

Multiple Prefab Instantiation, Camera, Button and Scroll View Question 1 Answer

Instantiating a prefab as a component type? 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