• 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 Tyler Starr · Nov 29, 2010 at 04:42 AM · nullreferenceexception

Script Error Helllp!

I have this Script:

var speed = 3.0; var rotateSpeed = 3.0; var bullitPrefab:Transform; function Update () { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0); var forward = transform.TransformDirection(Vector3.forward); var curSpeed = speed * Input.GetAxis ("Vertical"); controller.SimpleMove(forward * curSpeed); if(Input.GetButtonDown("Jump"))

         var bullit = Instantiate(bullitPrefab,      GameObject.Find("spawnPoint").transform.position, 
         Quaternion.identity);
         bullit.rigidbody.AddForce(transform.forward * 2000);

 }      

@script RequireComponent(CharacterController)

And I get this error:

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name) UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name) NewBehaviourScript.Update () (at Assets/Level Prefabs/NewBehaviourScript.js:15)

What Have I done wrong and how can I fix it?

Comment
Add comment · Show 5
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 Jesse Anders · Nov 29, 2010 at 04:45 AM 0
Share

Can you edit your post and fix the formatting?

avatar image Tyler Starr · Nov 29, 2010 at 04:50 AM 0
Share

There u go. Thanks!

avatar image BerggreenDK · Nov 29, 2010 at 05:01 AM 0
Share

what is the script supposed to be doing?

avatar image Tyler Starr · Nov 29, 2010 at 05:47 AM 0
Share

supposed to move a worm around and shoot fire balls out the front

avatar image Jesse Anders · Nov 29, 2010 at 03:33 PM 0
Share

Does the prefab pointed to by 'bullitPrefab' have a rigid body component attached to it?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by BerggreenDK · Nov 29, 2010 at 05:03 AM

Perhaps you need to assign a prefab to the script?

The script states in the top that you have a public variable called : "bullitPrefab" which is a Transform object, so you need to drag the wanted object it should control onto the script in the Inspector.

(I think)

Comment
Add comment · Show 3 · 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 Tyler Starr · Nov 29, 2010 at 05:16 AM 0
Share

Didnt seem to help any other ideas??

avatar image BerggreenDK · Nov 29, 2010 at 06:55 AM 0
Share

what codeline is this error ???

"NewBehaviourScript.Update () (at Assets/Level Prefabs/NewBehaviourScript.js:15)"

Find the .JS file and go to line 15 and post it here, please

avatar image Tyler Starr · Nov 29, 2010 at 05:43 PM 0
Share

This is it: bullit.rigidbody.AddForce(transform.forward * 2000);

avatar image
0

Answer by zannghast · Dec 14, 2010 at 02:28 AM

Could be that you were trying to include a Transform as the first parameter in a call to the Instantiate function:

bullit = Instantiate(bullitPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);

In the line above, bullitPrefab is still considered an object of type Transform, and not of a GameObject (which should be the type of first parameter in a call to Instantiate()).

Can you try doing this instead and see if it works:

bullit = Instantiate(bullitPrefab.gameObject, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);

Alternatively, assuming the above suggestion works, you could change the declaration of bullitPrefab to GameObject instead.

Somebody correct me if I'm wrong, thanks.

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 Nynex71 · Jan 02, 2011 at 09:09 PM

is your script even saved as JavaScript? the tornado twins code in JavaScript it looks to me that you might of accidentally made it in boo. Try to re-paste it into a JavaScript file.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How could I instantiate to a GameObject variable in a class? 1 Answer

Instantiate throws NullReferenceException 1 Answer

Instantiate example gives UnassignedReferenceException error 0 Answers

What is a null reference camera error exception? 2 Answers

NullReferenceException Reference Error - Please HELP! / How to fix? 3 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