Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 GenericFantasy · Jun 23, 2011 at 09:19 PM · gamenullreferenceexceptiontornado-twinsmissingmethodexceptionworm

Missing Method Exception and Null Reference Exception

I was going through the tornadotwins tutorials on youtube, and for some reason their scripts keep giving me errors? I solved most of them but 2, a Missing Method Exception and Null Reference Exception.

The Missing Method Exception applied to my Turret control script, heres the script

 var LookAtTarget : Transform;
 var damp : float = 6.0;
 var bullitPrefab : Transform;
 var savedTime = 0;
 
 function Update ()
 {
      if(LookAtTarget)
      {
           var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position); 
           transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp); 
           var seconds : int = Time.time;
           var oddeven = (seconds % 2);
           if(oddeven) 
               Shoot(seconds);
                 transform.LookAt(LookAtTarget);
      }
 
 }
 
 function Shoot(seconds)
 {
      if(seconds!=savedTime)
      {
           var bullit = Instantiate(bullitPrefab,transform.Find("TurretSpawnPoint").transform.position , Quaternion.identity);
           bullit.rigidbody.Addforce(transform.forward * 1000); 
      }
      savedTime=seconds;

}

And the error:

MissingMethodException: Method not found: 'UnityEngine.Rigidbody.Addforce'. Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher () Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create () Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args) Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args) Boo.Lang.Runtime.RuntimeServices+c_AnonStorey12.m_6 > () > Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get > (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey > key, > Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory > factory) > 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.Invoke > (System.Object target, System.String > name, System.Object[] args) > UnityScript.Lang.UnityRuntimeServices.Invoke > (System.Object target, System.String > name, System.Object[] args, > System.Type scriptBaseType) > TurretControl.Shoot (System.Object > seconds) (at > Assets/Scripts/TurretControl.js:26) > TurretControl.Update () (at > Assets/Scripts/TurretControl.js:15)Assets/Scripts/TurretControl.js:15)

The next is a NullReferenceException for my MoveAround Script, heres the script, It took a while to get a solution for this. I dont know why the scripts arent working for me, they seem to work fine for most people...

 var speed = 3.0;
 var rotateSpeed = 3.0;
 
 function Update ()
 {
     var controller : CharacterController = GetComponent(CharacterController);
     var forward = transform.TransformDirection(Vector3.forward);  
     var curSpeed = speed * Input.GetAxis ("Vertical");
 
     controller.SimpleMove(forward * curSpeed);    
     transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);    
 
     if(Input.GetButtonDown("Fire1"))
     {        
          Instantiate (GameObject.Find("BubblePrefab"),
             GameObject.Find("SpawnPoint").transform.position, 
             Quaternion.identity);  
 
     }
 }
 
 @script RequireComponent(CharacterController)

And le error... NullReferenceException UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/BaseClass.cs:46) UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/BaseClass.cs:57) MoveAround.Update () (at Assets/Scripts/MoveAround.js:15)

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Borgo · Jun 23, 2011 at 09:23 PM

MissingMethodException: Method not found: 'UnityEngine.Rigidbody.Addforce' The correct is AddForce, with "F" and not "f".

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 GenericFantasy · Jun 23, 2011 at 09:29 PM 0
Share

... facepalm Well now i feel like an idiot, it took ages for me to attempt to figure it out, and thats all it was? Idiot me....

avatar image
1

Answer by save · Jun 23, 2011 at 09:37 PM

The missing method is because Unity is case-sensitive, you call:

 bullit.rigidbody.Addforce

when it should say:

 bullit.rigidbody.AddForce

The second error is most likely that you've not wrapped up your prefab into a variable. Have a look at Instantiating Prefabs at Runtime in the docs.

On lines 15-17, instead of doing this:

 Instantiate (GameObject.Find("BubblePrefab"),
 GameObject.Find("SpawnPoint").transform.position, 
 Quaternion.identity); 

you should do this:

 Instantiate (bubblePrefab, spawnPoint.transform.position, Quaternion.identity);

Where you first declare bubblePrefab and spawnPoint as variables outside the Update-function:

 var bubblePrefab : GameObject;
 var spawnPoint : Transform;

Comment
Add comment · Show 2 · 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 GenericFantasy · Jun 23, 2011 at 09:57 PM 0
Share

Now it says The referenced script on this Behaviour is missing! UnityEngine.Object:Instantiate(Object, Vector3, Quaternion) $$anonymous$$oveAround:Update() (at Assets/Scripts/$$anonymous$$oveAround.js:17)

And it wont let me assign the spawn point i created to the script. Its an empty gameobject just in front of the character

avatar image save · Jun 27, 2011 at 09:59 AM 0
Share

$$anonymous$$ake sure that the var spawnPoint is set as : Transform in the script (as provided in the example).

avatar image
0

Answer by XXXar300500XXX · Jun 01, 2013 at 10:30 AM

on the first on i did have AddForce

but u keep getting this error NullReferenceException UnityEngine.Component.get_transform () (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineComponent.cs:21) ControlTurret.Shoot (System.Object seconds) (at Assets/Turret/ControlTurret.js:30) ControlTurret.Update () (at Assets/Turret/ControlTurret.js:19)

my javascript:

var LookAtTarget:Transform; var damp = 1; var bullitPrefab:Transform; var saveTime=0;

function Update () {

     if(LookAtTarget)
     {
             var rotate =Quaternion.LookRotation(LookAtTarget.position - transform.position);
             
             transform.rotation = Quaternion.Slerp(transform.rotation,rotate,Time.deltaTime * damp);
             
             var seconds:int = Time.time;
             var oddeven =  (seconds % 2);
             
             if(oddeven)
             {
                     Shoot(seconds);
             }
             
             
     }

}

function Shoot(seconds) {
if(seconds != saveTime) { var bullit = Instantiate(bullitPrefab, transform.Find("spawnpoint").transform.position, Quaternion.identity);

             bullit.rigidbody.AddForce(transform.forward  * 1000);
     
             saveTime=seconds;
     }

}

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Null Reference Exception Hunt ! 1 Answer

TornadoTwins Tutorial 1 Answer

how to create Objectives 1 Answer

Enemies Problem 1 Answer

GUI_TEXTURE PROBLEM! 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