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 /
  • Help Room /
This question was closed Sep 24, 2016 at 04:39 PM by sadzanenyama for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by sadzanenyama · Sep 24, 2016 at 01:54 PM · javascriptscripting problemgameobjectfps

Bullet trying to set object that doesn't even exist

My bullet is trying to set the game object "gun" to a game object that doesn't even exist in my assets what so ever. alt text

Shotgun2 doesn't even exist in my scene!

alt text

It comes up with the error

NullReferenceException: Object reference not set to an instance of an object BulletScript.Awake () (at Assets/BulletScript.js:23) UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)

When I double click on the error it sends me here. Highlighting "if(gun.GetComponent(Gun).aiming == true)"

Bullet Script:

 #pragma strict
 
 var bulletHole : GameObject;
 var floatInFrontOfWall : float = 0.001;
 var maxDist : float = 10000000000;
 var Enemy : GameObject;
 var maxDamage : float = 15;
 var minDamage : float = 5;
 
 var gun : GameObject;
 var blood : GameObject;
 
 //Accuracy
 var minAimAccuracy : float;
 var maxAimAccuracy : float;
 var minHipAccuracy : float;
 var maxHipAccuracy : float;
 
 function Awake () {
     
     gun = GameObject.FindWithTag("Gun");
 
     if(gun.GetComponent(Gun).aiming == true)
     {
         transform.rotation.eulerAngles.y += Random.Range(minAimAccuracy, maxAimAccuracy);
         transform.rotation.eulerAngles.x += Random.Range(minAimAccuracy, maxAimAccuracy);
     }   
     if(gun.GetComponent(Gun).aiming == false)
     {
         transform.rotation.eulerAngles.y += Random.Range(minHipAccuracy, maxHipAccuracy);
         transform.rotation.eulerAngles.x += Random.Range(minHipAccuracy, maxHipAccuracy);
     }   
 }
 
 function Update () {
     var hit : RaycastHit;
     var damage = Random.Range(minDamage, maxDamage);
     if(Physics.Raycast(transform.position, transform.forward,hit, maxDist))
     {
         if(bulletHole && hit.transform.tag == "Terrain")  
             Instantiate(bulletHole, hit.point +(hit.normal * floatInFrontOfWall),Quaternion.LookRotation(hit.normal));
         if(hit.transform.tag == "Enemy")    
         {
             Enemy  = hit.collider.gameObject;
 
         }
         if(Enemy)
             Enemy.GetComponent(EnemyHealth).currentHealth -= damage;
     }
     Destroy(gameObject);
 }


I have other objects in my scene with the tag "Gun" but it doesn't seem to want to use those Please help!

inspector.jpg (25.7 kB)
shotgun.jpg (21.7 kB)
Comment
Add comment · Show 1
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 sadzanenyama · Sep 24, 2016 at 02:08 PM 0
Share

Well if I set all the weapons to another tag and change the bullet script to the new tag name it works. But it seems my tag 4 is bugged and no matter what is tagged with "weapon" it will always set it to this mysterious "shotgun(2)"

1 Reply

  • Sort: 
avatar image
0

Answer by Trevdevs · Sep 24, 2016 at 03:00 PM

Unless that first photo was taken during runtime your Gun object is already set to "Shotgun2(Clone)" set that to none and it should hunt the scene for the object with the tag "Gun"

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 sadzanenyama · Sep 24, 2016 at 04:39 PM 0
Share

Thanks for the reply! This was taken during runtime. I manged to fix it (sort of as any object using tag 4 will never be noticed. It will always only use Shotgun2(Clone) and I can't just delete the tag and make a new tag as any tag in tag slot 4 will like I said never be noticed. So I just have to waste 1 tag slot :C) I will close down the question now as it seems to be some kind of bug with tagging blender made objects, but I really do appreciate your answer!

Follow this Question

Answers Answers and Comments

114 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Having multiple UNET errors that I believe are caused by unity itself. Am I doing something wrong? 1 Answer

how to move a gameobject based on a dice roll 1 Answer

Template object and script,GameObject scripts duplicated from a template game object 0 Answers

Infinite floor with object as terrain. 1 Answer

Running C# Function from JS file 0 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