Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  3. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    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)