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
-1
Question by Blazeda59 · Jun 11, 2010 at 12:41 PM · respawn

Respawn Code Null Reference Exception

Hi this is just a small problem Im having, I did have it solved earlier today in class by like an idiot I saved an older version over my fixed code and now cant remember how my teacher fixed it so any help will be much appreciated.

public class Respawn : MonoBehaviour

{

public MarbleControls theMarble; public int respawnTime; public Vector3 floatTime; public GameObject blood; public Vector3 scaleSpeed; public bool invokeToggle; public GameObject thingToFollow; public GameObject destroy; public AudioClip RespawnPlay; public AudioClip ImpactPlay; public AudioClip DeathPlay;

public void OnTriggerEnter(Collider other) {

 if (other.tag == "Player")
 {
     //If fallen then check to see if respawn hasnt been invoked
     if (invokeToggle == false)
     {

         //Invoke respawn and set the toggle to true                               
         Invoke("RespawnMarble", respawnTime);
         blood.gameObject.active = true;
         Instantiate(blood, other.transform.position, other.transform.rotation);
         //Set the toggle to true
         invokeToggle = true;

//The Error starts here so the next script "MarbleControls" wont Invoke respawn but the GameObject is deactivated

---destroy.active = false;--- audio.PlayOneShot(ImpactPlay); audio.PlayOneShot(DeathPlay); } } }

public void OnTriggerStay(Collider other) {

 theMarble.transform.localScale.Scale(scaleSpeed);
 theMarble.rigidbody.AddForce(floatTime);

}

public void RespawnMarble() { //Respawn marble theMarble.RespawnMarble(); blood.active = false; //Marble has been respawned so set the invoke to false invokeToggle = false; audio.PlayOneShot(RespawnPlay); }

}

**MarbleControls Script**

public class MarbleControls : MonoBehaviour

{

public Vector3 spawnPoint;

// Use this for initialization

void Start()

{ rigidbody.maxAngularVelocity = 25; }

// Update is called once per frame void Update() { //Debug.Log("You Pressed W"); if (Input.GetKey(KeyCode.W)) { rigidbody.AddForce(0, 0, -5); } //Debug.Log("You Pressed S"); if (Input.GetKey(KeyCode.S)) { rigidbody.AddForce(0, 0, 5); } //Debug.Log("You Pressed A"); if (Input.GetKey(KeyCode.A)) { rigidbody.AddForce(5, 0, 0); } //Debug.Log("You Pressed D"); if (Input.GetKey(KeyCode.D)) { rigidbody.AddForce(-5, 0, 0); } } // Respawns the marble public void RespawnMarble() {

//This is where the last script is supposed to invoke Respawn but fails because the next line is wrong

    ---transform.parent.gameObject.active = true;--- 
    rigidbody.MovePosition(spawnPoint);
    rigidbody.velocity = new Vector3(0, 0, 0);
    rigidbody.angularVelocity = new Vector3(0, 0, 0);
}

}

My teacher changed something on the 2 lines I've tagged, I think it may only be the line in MarbleControls but I cant remember and Im not good enough at programming to figure it out. I can remember the line was quite long but thats about it lol.

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
1

Answer by noony · Jun 11, 2010 at 01:12 PM

If you are getting a null reference exception on the line...

transform.parent.gameObject.active = true;

...this would most likely be because the GameObject that your MarbleControls script is attached to does not have a parent GameObject.

Alternatively, if you have not set the public variable destroy in your first script to refer to anything, that would also result in a null reference exception at the other line you have tagged.

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 Blazeda59 · Jun 11, 2010 at 02:26 PM 0
Share

thanks for the quick reply all I had to do was remove parent from the line. I knew it was only a little problem cheers for ya help

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

No one has followed this question yet.

Related Questions

Stop Object from deleting HELP ME!!!!!!!!!!!! 1 Answer

Respawn question unanswered 0 Answers

instantiated objects animation making the object reset to 0,0,0?? 1 Answer

Respawn with enemy contact 1 Answer

OnTriggerEnter forcefield help! 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