• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Dreoh · Apr 05, 2012 at 03:09 AM · raycastcomponenthitmelee

Yet another NullReferenceException question.

Edit: I figured out t$$anonymous$$s 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 w$$anonymous$$le 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 $$anonymous$$t : RaycastHit;
      var fwd = transform.TransformDirection

(Vector3.forward);

      if(Physics.RayCast (transform.position, fwd, $$anonymous$$t,

playerAttackRange)){ if($$anonymous$$t.collider.gameObject == null){ Debug.Log("collided with "+$$anonymous$$t.name+" w$$anonymous$$ch has no DamageManagement!"); }else{ if($$anonymous$$t.collider.gameObject.tag == "Enemy") { $$anonymous$$t.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.DynamicDispatc$$anonymous$$ng.MethodDispatcherFactory.ProduceExtensionDispatcher () Boo.Lang.Runtime.DynamicDispatc$$anonymous$$ng.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.DynamicDispatc$$anonymous$$ng.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatc$$anonymous$$ng.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatc$$anonymous$$ng.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatc$$anonymous$$ng.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatc$$anonymous$$ng.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)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Kleptomaniac · Apr 05, 2012 at 03:31 AM

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

Comment
Add comment · Show 7 · 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 Dreoh · Apr 05, 2012 at 03:35 AM 0
Share
avatar image Kleptomaniac · Apr 05, 2012 at 03:46 AM 0
Share
avatar image Dreoh · Apr 05, 2012 at 01:38 PM 0
Share
avatar image Dreoh · Apr 05, 2012 at 03:58 PM 0
Share
avatar image Kleptomaniac · Apr 05, 2012 at 04:01 PM 0
Share
Show more comments
avatar image
0

Answer by Datael · Apr 05, 2012 at 06:26 AM

I might be wrong about t$$anonymous$$s 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.

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 Dreoh · Apr 05, 2012 at 01:58 PM 0
Share

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

NullReferenceException: Object reference not set to an instance of an object Raycast...? 1 Answer

Raycast Destroy(hit.collider.gameObject); (Still need help) 1 Answer

What is wrong with this melee system? 1 Answer

GetComponent(Script) Error(Won't detect script) 0 Answers

swing to hit a target 1 Answer


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