Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Tenate · Nov 24, 2014 at 03:58 AM · 2djavascriptinstantiatenullreferenceexceptionitween

iTween NullReferenceException error

I have run into a problem that is now bugging the hell out of me. I am making a 2D Space Shooter at the moment and I made a randomdrop script and a enemy ship script which I made drop the random drop chosen upon death. I only kept this script on one ship while testing and working out the kinks and it worked fine. This is why it confuses me. I'm using the exact same script on the exact same ship, unchanged, but when I added it to the other ships and made other few minor changes it stopped the game upon dropping the boost and the enemyship getting destroyed and gave me this error:

 NullReferenceException: Object reference not set to an instance of an object
 iTween.RetrieveArgs () (at Assets/Plugins/Pixelplacement/iTween/iTween.cs:6812)
 iTween.Awake () (at Assets/Plugins/Pixelplacement/iTween/iTween.cs:6559)
 UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)
 Bantera1script:Update() (at Assets/Level1/Scripts/Bantera1script.js:49)

I can then proceed to unpause the game and it will work like as if nothing happened and then when another ship gets killed and happens to drop a boost it happens again. This is extremely irritating and I have rolled back all the changes from the point when I added it to the other ships and still no fix. Here are my enemy ship and randomdrop scripts:

Random drop script:

 #pragma strict
 
 var rdsSelect:int;
 static var dropType:boolean[];
 static var scoreMult:boolean;
 
 function Start () {
     dropType = [false,false];
     scoreMult = false;
     SelectRandomNumber();
 
     if(rdsSelect <= 6){
         //Player gets nothing
         dropType[0] = true;
     }
     if(rdsSelect <= 10 && rdsSelect >= 7){
         dropType[1] = true;
     }
 }
 
 function Update () {
 }
 
 function SelectRandomNumber () {
     rdsSelect = Random.Range(1,10);
 }

Enemy Ship:

 #pragma strict
 
 var speed:float;
 var player:playerscript;       //Variable to link to the players script
 var bullet:Transform;
 var canShoot:boolean = true;
 var gun1:Transform;
 var gun2:Transform;
 var hp:int;
 var shot:AudioSource;
 var damage:AudioSource;
 static var rdsDrop:int;
 
 function Start () {
     var multSources : AudioSource[] = gameObject.GetComponents.<AudioSource>();
     shot = multSources[0];
     damage = multSources[1];
     player = GameObject.FindGameObjectWithTag("Player").GetComponent(playerscript);
     hp = 3;
     iTween.MoveTo(gameObject,{"y":12,"time":4,"delay":1});
     iTween.MoveTo(gameObject,{"x":-21,"y":12,"time":3,"delay":5});
     iTween.MoveTo(gameObject,{"x":21,"time":10,"delay":10});
     if(randomdrop.dropType[0] == true){
         Debug.Log("No Drop");
     }
     if(randomdrop.dropType[1] == true){
         SelectRandomDrop();
         Debug.Log("dp" + rdsDrop);
     }
 }
 
 function Update () {
     var dp1 = GameObject.Find("2xboost");
     var dp2 = GameObject.Find("healthboost");
     var dp3 = GameObject.Find("superboost");
     var dp4 = GameObject.Find("clearboost");
     var enemyObject = GameObject.Find("bantera1");
     var    enemyPos:Vector3 = enemyObject.transform.position;    
     if(canShoot == true) {
         Instantiate(bullet,gun1.position,Quaternion.identity);
         Instantiate(bullet,gun2.position,Quaternion.identity);
         canShoot = false;
         shot.Play();
         Reload();
     }
     if(hp <= 0){
         Death();
         if(rdsDrop == 1){
             Instantiate(dp1,enemyPos,Quaternion.identity);
         }
         if(rdsDrop == 2){
             Instantiate(dp2,enemyPos,Quaternion.identity);
         }
         if(rdsDrop == 3){
             Instantiate(dp3,enemyPos,Quaternion.identity);
         }
     }
 }
 
 function Reload () {
     yield WaitForSeconds(1.5);
     canShoot = true;
 }
 
 function OnTriggerEnter2D(other:Collider2D){
     //Check to see if what we hit was the player
     if(other.tag == "Player") {
         player.hp --;
         hp --;
         //Play damage sound
         damage.Play();
     //If player bullet hits destroy bullet and ship
     }
     if(other.tag == "Bullet") {
         if (randomdrop.scoreMult == false){
             //Add points to player score
             player.score += 1;
             playerscript.denarii += 2;
         }else{
             player.score /= .9;
         }
         damage.Play();
         //Destroy the bullet
         Destroy(other.gameObject);
         hp --;
     }    
     if(other.tag == "Bullet2") {
         if (randomdrop.scoreMult == false){
             player.score += 2;
             playerscript.denarii += 3;
         }else{
             player.score /= .8;
         }
         damage.Play();
         Destroy(other.gameObject);
         hp -= 2;
     }    
     if(other.tag == "Bullet3") {
         if (randomdrop.scoreMult == false){
             player.score += 3;
             playerscript.denarii += 4;
         }else{
             player.score /= .7;
         }
         damage.Play();
         Destroy(other.gameObject);
         hp -= 3;
     }
 }
 
 function SelectRandomDrop () {
     rdsDrop = Random.Range(1,3);
 }
 
 function Death () {
         damage.Play();
         Destroy(gameObject);
 }

I'm thinking about re-doing the way I made it and instead of calling the boost from the GameObjects, making a transform variable and just putting the boost prefabs in there for spawning. Hopefully there's a way to fix this without doing that though.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jeepcreep · Mar 22, 2016 at 01:48 PM

I know this question is grand-old but still it seems you just forgot initializing the iTween handler on the gameObject itself as is documented here:

http://itween.pixelplacement.com/documentation.php#Init

It's important to do it inside the Awake() method of a gameObject's/PreFab's scripts.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Instanciate Object Problem for Shooting 2 Answers

NullReferenceException with MoveObject.js 1 Answer

2D Space Shooter Instantiating bullet question 1 Answer

Unity iOS Javascript - Problem with Instantiate 1 Answer

OnTriggerEnter2d not working 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