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 /
avatar image
0
Question by zack1990 · Dec 09, 2018 at 03:25 AM · collisionprefabsreferencing

Player suddenly not registered by anything?

This is a bit of a long one so bear with me. Any help would be immensely appreciated. This is for a school project.

So I was working on trying to find a way to get the player's death sound to play after the game is paused using Time.timeScale = 0. I couldn't figure out how to get it to work, so I deleted that code. Now, suddenly, everything related to the player is completely broken. I have pored over each and every line of every script in my game, and cannot seem to find the issue. I even took a break, went outside, had some dinner, came back and did it again. I simply cannot figure it out.

Important info:

1) The player object is tagged as "Player". It is not deactivated and is currently in the scene.

2) The player bullet object is tagged as "PlayerBullet."

3) The player, the player's bullets, and the enemies all have RigidBodies and colliders attached. None of them are checked as triggers or kinematic.

4) The script that controlled the enemies looking at the player was not changed.

5) Every GameObject in the scene was placed there from their prefabs, with the scripts in place and all necessary fields filled with the necessary items. I checked each one individually just to make sure.

What I have found:

1) I have two scripts that work off of two of the player's values, health and shield, which update the image in the canvas. They reference these values from a script that is attached to the player using FindObjectWithTag("Player"), and then they access its health or shield variable. They are suddenly throwing a NullReferenceException.

2) I had a script that made the enemies always look at the player in the Update section using transform.LookAt (player.transform). They now face the opposite direction of their prefab when placed, when originally they followed the prefab's values. There is no error thrown. I tried to use Debug.Log to tell me if the player actually existed in the script's eyes, and it gave a "yes" even when I removed the player from the scene.

3) These enemies would shoot at the player by following the player's transform, but now shoot in a straight line in the same direction they are facing as they are not turning.

4) The player's bullets used to ricochet off of the enemy once hit, but now go straight through it as though it was not there.

5) The enemies used to die after two hits and play an explosion sound. At first when everything went haywire, the enemies would suddenly be killed in one shot instead of two. It may be that the bullet was going through them instead of ricocheting, everything hadn't broken yet so I wasn't paying complete attention to that. They both had their health set to 2 and this field was not altered. Both enemies behaved in the exact same way after testing this several times. Now the bullets do not affect the enemies so I cannot test this anymore.

6) The script that adjusted the enemy health did so by finding a collision with object tagged "PlayerBullet." Since the bullets have started going through the enemies, this script is no longer being activated like it should. The enemies do not die at all anymore. 6) I tried changing the health and shield canvas object to use the Find("Player") instead of FindObjectsWithTag, but it still did not work.

Tldr;

Nothing seems to be registering the objects tagged "Player" or "PlayerBullet" anymore, and any physics collisions involving the player or bullets are suddenly broken even with the RigidBodies and colliders in place. I have tried removing it and placing it back into the scene. The player's movement and shooting works fine, but the game is simply acting like the player and their bullets are no longer there. The healthbars cannot reference the player object's health, and the enemies cannot be shot by or look at the player, even though it is right there, tagged and everything. All of this worked fine up until I tried to mess with stopping Time and adding a sound.

Before blasting a million lines at code and asking that people sift through it all, is there anything I could try that I have not thought of?

Here are the two bits of code that are specifically not working......

Health meter's script used to reference the player (which was untouched and now throws NullReference):

GameObject player = GameObject.FindGameObjectWithTag ("Player");

currentHealth = player.GetComponent ();

switch (currentHealth.health) { <------ this is where the exception points to

Enemy's look at script (which was untouched and now does nothing):

void Start () {

InvokeRepeating ("Shoot", 2.0f, 1.0f);

player = GameObject.FindWithTag ("Player");

}

void Update () {

transform.LookAt (player.transform);

}

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

0 Replies

· Add your reply
  • Sort: 

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

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

Collision Detection between two different Prefabs doesnt work 1 Answer

Advance Colision Detection 1 Answer

Any other ways for instantiated prefabs to reference game-objects in the scene? 0 Answers

attaching prefabs together at runtime 0 Answers

Referencing Base Class In Prefab 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