Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Raycast hitting a destroyed object

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

  1. tornado147


    Jan 16, 2018
    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


    Apr 6, 2017
    Code or gtfo.

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