x


Yet another NullReferenceException question.

Edit: I figured out this problem, but I have a new problem I stated at bottom of post

Ok, its my first time programming a game and I'm following a tutorial, but changing the scripts I made following it around to match my game.

I'm trying to script a melee attack, and while I get no errors and can press play and the particles from the melee script are instantiated, no damage is actually done, and the log gets spammed with

NullReferenceException: Object reference not set to an instance of an object AbilitySystem.checkFireValues () (at Assets/Custom Assets/Scripts/Player/AbilitySystem.js:30) AbilitySystem.Update () (at Assets/Custom Assets/Scripts/Player/AbilitySystem.js:23)

I have tried changing it around it seems a hundred times, so I came here to see for some advice. Any help is very much appreciated! :)

scripts - >

MeleeAttack.js

var countdown : int = 2;
var playerAttackRange : int = 2;
var particle : GameObject;
var player : GameObject;


function Start () {

}

function Update () {
    var particleClone = particle;
    if(countdown > 0){
       countdown -= Time.deltaTime;
       }
    if(countdown <= 0){
       countdown = 2;
       }

    if(Input.GetButton("Fire1")){
       particleClone = Instantiate(particle,

transform.position, transform.rotation); Destroy(particleClone, 1); attack(); }

}

function attack(){
    if(AbilitySystem.fireElement.equippedFire

== true) {

    var hit : RaycastHit;
    var fwd = transform.TransformDirection

(Vector3.forward);

    if(Physics.RayCast (transform.position, fwd, hit,

playerAttackRange)){ if(hit.collider.gameObject == null){ Debug.Log("collided with "+hit.name+" which has no DamageManagement!"); }else{ if(hit.collider.gameObject.tag == "Enemy") { hit.collider.gameObject.GetCompponent(EnemyHealth).enemyCurrentHealth -= AbilitySystem.fireElement.swordDamage; } } } } }

AbilitySystem.js

#pragma strict

function Start () {

}



class fireElementClass {
    var equippedFire : boolean = true;
    var fireLevel : int = (swordLevel + plummetLevel + meteorLevel)/3;
    var swordLevel : int = 1;
    var plummetLevel : int = 1;
    var meteorLevel : int = 1;
    var swordDamage : int = 1;
}

static var fireElement : fireElementClass;


function Update () {

    checkFireValues();

}


function checkFireValues(){

    fireElement.swordDamage *= Statistics.levelModifier *

((fireElement.fireLevel * fireElement.swordLevel)/2);

}

I wanted to figure it out myself... but I concede defeat >_>

Edit: OK, well I figured that part out, now when I use my melee attack, apparently there is some error with the Physics.Raycast

MissingMethodException: Method not found: 'UnityEngine.Physics.RayCast'. 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.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args) MeleeAttack.attack () (at Assets/Custom Assets/Scripts/Player/MeleeAttack.js:35) MeleeAttack.Update () (at Assets/Custom Assets/Scripts/Player/MeleeAttack.js:24)

more ▼

asked Apr 05 '12 at 03:09 AM

Dreoh gravatar image

Dreoh
49 7 10 12

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

2 answers: sort voted first

I believe the problem is that you don't appear to be declaring a class variable Statistics anywhere, and therefore the compiler is unable to find values for Statistics.levelModifier and throws a NullReferenceException.

That's from what I can see anyway ... is Statistics a static var in another script?

Hope that helps, Klep

more ▼

answered Apr 05 '12 at 03:31 AM

Kleptomaniac gravatar image

Kleptomaniac
2.5k 6 12 21

Yea, Statistics is a script on my player with static variables I use as a kind of central hub for basic information

Apr 05 '12 at 03:35 AM Dreoh

Well, I did just find one issue ... You have spelt GetComponent wrong in MeleeAttack.js when you're trying to find the EnemyHealth script ... may just be a copypasta error though ...

Apr 05 '12 at 03:46 AM Kleptomaniac

yea that was just a copypasta error lmao

Apr 05 '12 at 01:38 PM Dreoh

do you have any idea what this new issue is?

I pasted it at the bottom of original post

Apr 05 '12 at 03:58 PM Dreoh

Haha, yep, I found what's wrong. Should be "Raycast" as opposed to "RayCast". :P

Apr 05 '12 at 04:01 PM Kleptomaniac
(comments are locked)
10|3000 characters needed characters left

I might be wrong about this since I use C#, not JS, but you don't appear to be instantiating fireElement with a new anywhere in AbilitySystem.js so the static will always be null.

more ▼

answered Apr 05 '12 at 06:26 AM

Datael gravatar image

Datael
555 2 5

That isn't necessarily a problem in java

And I figured the original problem out... but now a new one lol

Apr 05 '12 at 01:58 PM Dreoh
(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:

x3416
x1579
x312
x194
x70

asked: Apr 05 '12 at 03:09 AM

Seen: 534 times

Last Updated: Apr 05 '12 at 09:52 PM