Search Unity

Raycast hitting a destroyed object

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

  1. RowanberryPrints

    RowanberryPrints

    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. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Code or gtfo.

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