Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Raycast hitting a destroyed object

Discussion in 'Physics' started by tornado147, Dec 4, 2018.

  1. tornado147

    tornado147

    Joined:
    Jan 16, 2018
    Posts:
    1
    Hi all,

    I'm having a problem within a foreach loop.

    I'm iterating through a list of objects, and for each of those objects i'm spawning a sphere and firing a ray at the sphere multiple times in different directions, and then logging where the ray hit. After that im destroying the sphere and moving on to a different object and doing the same.

    The problem im having is that when debugging, i can see that the rays are hitting spheres that have already been destroyed. Do destroyed objects still leave their collider in the physics world until the end of the frame or something? That's the only thing i can think of.

    Any ideas would be appreciated.
    Many thanks
     
  2. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    1,491
    Code or gtfo.

    Cant help you if we dont see the problem, what are you trying to do exactly?(gameplay-wise)