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 C-Blunt · Apr 15, 2012 at 11:19 PM · collisiondestroynullmissingreferenceexception

MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.

Hi, I'm making a doodle jump style game as my first unity project. The game begins and the platform boosts your jump speed and gets destroyed when you hit it which is fine but unity is returning the following error and no more platforms are spawned. From what I've read i need to set the destroyed platform to null, but im not sure how to do this...Please help!

"MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it."

using UnityEngine; using System.Collections;

public class Playermovement : MonoBehaviour { public float movementSpeed = 8.0f;

 void Update() {
     rigidbody.velocity = new Vector3(0, rigidbody.velocity.y, 0); //Set X and Z velocity to 0
 
     transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime * movementSpeed, 0, 0);
 }

 void Jump() //Increases velocity of player when called.
 {
     rigidbody.velocity = new Vector3(0, 0, 0);
     rigidbody.AddForce(new Vector3(0, 700, 0), ForceMode.Force);        
 }
 void OnCollisionEnter(Collision collision){
 if(collision.gameObject.tag == "platform")
 {
     Jump ();
     Destroy(collision.gameObject); 
 }

}

Comment
Add comment · Show 3
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 Lttldude · Apr 15, 2012 at 11:23 PM 0
Share

Is the platform's movement being controlled by another script? Are there any other scripts that are using the platform?

avatar image Owen-Reynolds · Apr 16, 2012 at 03:14 AM 1
Share

What line of what script is the error on?

When you destroy the platform, any scripts on it also die, so no issues there. But, suppose someone else has Transform P; which was set the that platform. After the player destroys it, that guy is left with P pointing to nothing (Unity automatically nulls P for you.)

avatar image Kryptos · Apr 23, 2012 at 09:23 AM 0
Share

@owen-reynolds

Unity automatically nulls P for you

Actually, no. Unity does not, and that's a case for memory leaks. But Unity does detect that the object was previously destroyed, hence the error message.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by C-Blunt · Apr 22, 2012 at 09:38 PM

Solved it now, Owen Reynolds was correct so many thanks to you! My script for respawning platforms was still trying to access the deleted platform clones.

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
avatar image
0

Answer by FizzyBear · Apr 15, 2012 at 11:24 PM

Why don't you create a clone prefab? Then access that in the code? Destroy the clone while keeping the main object..

You could use the following as an example..

  var projectile : Transform;
 var bulletSpeed : int = 100;
 
 function Update () 
 {
     var fireBall = GameObject.Find("spawnPoint");
     // Put this in your update function
     if (Input.GetMouseButtonDown(0)) {
 
     // Instantiate the projectile at the position and rotation of this transform
     var clone : Transform;
     clone = Instantiate(projectile, fireBall.transform.position, transform.rotation);
 
     // Add force to the cloned object in the object's forward direction
     clone.rigidbody.AddForce(clone.transform.forward * bulletSpeed);
         
         Destroy(clone.gameObject, 1);    
    }
 }
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

7 People are following this question.

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

Related Questions

The object of type 'Transform' has been destroyed but you are still trying to access it. 0 Answers

script trying to access a null gameobject's collider... can't fix 2 Answers

Destroying object when player walks over it 1 Answer

How do I disable the gameobject by script? 2 Answers

Collision detection between two objects? 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