x


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)

more ▼

asked Jun 23 '11 at 09:19 PM

GenericFantasy gravatar image

GenericFantasy
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Jun 23 '11 at 09:23 PM

Borgo gravatar image

Borgo
998 9 13 25

... 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....

Jun 23 '11 at 09:29 PM GenericFantasy
(comments are locked)
10|3000 characters needed characters left

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;
more ▼

answered Jun 23 '11 at 09:37 PM

save gravatar image

save
8.2k 22 31 62

Now it says The referenced script on this Behaviour is missing! UnityEngine.Object:Instantiate(Object, Vector3, Quaternion) MoveAround:Update() (at Assets/Scripts/MoveAround.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

Jun 23 '11 at 09:57 PM GenericFantasy

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

Jun 27 '11 at 09:59 AM save
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x796
x394
x44
x20
x14

asked: Jun 23 '11 at 09:19 PM

Seen: 2771 times

Last Updated: Jun 27 '11 at 09:59 AM