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 foxt451 · Mar 21, 2021 at 05:47 PM · referencenulldestroyimmediate

Using DestroyImmediate on one GameObject makes a reference to another a null

I have a rope that consists of links, one attached to another. Each link (except for the first one) has a HingeJoint2D component, in which the connectedRigidbody field is set to the rigidbody of the previous link. I paint the rope with a custom brush that sets all connections automatically, but I'm trying to implement Erase method so that when I click on one link, the whole rope gets erased. I'm trying to do it traversing the rope by accessing connectedRigidbody and deleting links one by one:

 public override void Erase(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
 {
         GameObject toErase = GetGameobjectInCell(gridLayout, position, brushTarget.transform);
 
         while (toErase != null)
         {
             GameObject nextToErase = toErase.GetComponent<HingeJoint2D>()?.attachedRigidbody.gameObject;
             Debug.Log(nextToErase);
             DestroyImmediate(toErase);
             Debug.Log(nextToErase);
             toErase = nextToErase;
         }
 }

this is what the Debugger says: alt text And I wonder why after using DestroyImmediate on toErase, nextToErase becomes null

screenshot-1.png (7.6 kB)
Comment
Add comment · Show 4
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 logicandchaos · Mar 21, 2021 at 08:37 PM 0
Share

try SetActive(false); then delete the whole thing after.

avatar image foxt451 logicandchaos · Mar 22, 2021 at 09:17 AM 0
Share

didn't work

avatar image toficofi · Mar 22, 2021 at 09:30 AM 0
Share

This only traverses in one direction, right? So what happens when you click in the middle of the rope?

avatar image foxt451 toficofi · Mar 22, 2021 at 12:03 PM 0
Share

currenly it removes only one link wherever i click, but if it worked correctly, it would simply traverse from that link up and remove half of the rope. If I wanted to remove the whole rope, I would have to click at its end

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by foxt451 · Mar 22, 2021 at 01:26 PM

Well, it was actually very easy. I confused connectedBody with attachedRigidbody, the second one apparently refers to the same object.

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

116 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

Related Questions

Deleted object tagged as missing instead of null. 0 Answers

Null Reference Problem Code+pic (SOLVED) 2 Answers

ScriptableObject resets on Play 0 Answers

Null Reference Exception error 3 Answers

NullReferenceException - With Network PlayerSpawn 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