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 maroonfire · Feb 19, 2013 at 02:44 PM · error

Need help with this error

I am getting an error with this code saying variable prefabBullet isn't defined. Explain.

"#pragma strict

function Start () {

} var prefabBullet:Transform;

var shootForce:float;

function Update () {

 if(Input.GetButton("Fire1"))
 {
     var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
     instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
 }"
Comment
Add comment · Show 9
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 maroonfire · Feb 19, 2013 at 01:57 PM 0
Share

sorry for my newfaggy formating

avatar image BlackWingsCorp · Feb 19, 2013 at 02:56 PM 0
Share

if I'm not wrong prefabBullet must be a rigidbody

avatar image flaviusxvii · Feb 19, 2013 at 03:20 PM 0
Share

@BlackWingsCorp sorry.. you're wrong.

@maroonfire Can you post the exact error message the compiler gives you. And all of your code? Put it on Pastebin.com maybe?

avatar image maroonfire · Feb 19, 2013 at 03:24 PM 0
Share

@flavius it actually does have to be rigid body and here is the error word for word.

You probably need to assign the prefabBullet variable of the Shoot script in the inspector. UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:44) UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:53) Shoot.Update () (at Assets/Shoot.js:15)

avatar image maroonfire · Feb 19, 2013 at 03:27 PM 0
Share

here is the code

"#pragma strict

function Start () {

} var prefabBullet:Transform;

var shootForce:float;

function Update () {

if(Input.GetButton("Fire1")) { var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity); instanceBullet.rigidbody.AddForce(transform.forward * shootForce); } }

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by 1337GameDev · Feb 19, 2013 at 03:57 PM

Use resource.load to load the prefab at runtime or assign it via the inspector. Prefabs reference outside resource gameObjects. If you call instantiate on an unitialized prefab reference, it will give this error.

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

Answer by flaviusxvii · Feb 19, 2013 at 07:32 PM

In your initial explanation you said:

code saying variable prefabBullet isn't defined

And then when you pasted the actual message it said:

You probably need to assign the prefabBullet variable of the Shoot script in the inspector.

Something not being "defined" is a very different error than something not having a value set. It's best not to rephrase error messages when conveying them to others.

Assign a value to bulletPrefab in the inspector, and make sure the prefab you assigned has a rigidBody attached!

Comment
Add comment · Show 6 · 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 1337GameDev · Feb 19, 2013 at 07:48 PM 0
Share

Do not yell at other users. Especially new users. This forum is meant to encourage questions not chastize people for making mistakes in being clear. Just advise him to not change error messages or to just post exact console log message.

This is meant to be a learning community. A positive one that encourages question answering and asking. Please abide by what this community is meant to be.

avatar image flaviusxvii · Feb 19, 2013 at 08:05 PM 0
Share

$$anonymous$$y only interest is being helpful. If I didn't care I wouldn't bother commenting/answering. Editorializing warnings/errors from a compiler is a cardinal sin in clarity. Hence the BOLD UPPER CASE. Downvote me if you like. But I don't like coddling the new users and handing them code. They need to learn how to ask clear and specific questions.

avatar image 1337GameDev · Feb 19, 2013 at 08:17 PM 0
Share

Yes you can still not coddle a new user without yelling at them. BOLDING A STATE$$anonymous$$ENT IS YELLING ON THE INTERNET. Especially if its bold. You can $$anonymous$$ch somebody something without being negative. And handing a user a small snippet of code to correctly instantiate is easy and not coddling. They didn't know how to use a function or know that you had to use it a certain way. If he asked for shooting a bullet and making it explode on impact, I can understand you want him to learn by coding himself. But I think acting this way on principle for something so petty is immature.

Just please treat all users positively in the future please. When I started out, I hated people like you that would make it a negative experience to learn.

avatar image maroonfire · Feb 19, 2013 at 11:52 PM 0
Share

thx, it worked asshole

avatar image flaviusxvii · Feb 19, 2013 at 11:56 PM 0
Share

I edited my post top be less of an asshole.

Also, I think you mean "it worked, asshole". Critical comma there. ;)

Show more comments

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

12 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

Related Questions

Error on Roll a Ball script Assets/scripts/playercontroller.cs(26,1): error CS8025: Parsing error 1 Answer

Raycast error 1 Answer

'position' is not a member of 'object' 2 Answers

Error CS1525: Unexpected Symbol `int' 0 Answers

Attaching objects to objects In game 0 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