- Home /
Raycast not hitting instantiated object when timescale is 0
My raycasting has 3 possible hits - UI, empty space or some game object that I spawn.
The game begins with timescale as 0 since it requires the user to select some configuration which then spawns the objects. At this step after spawning objects but before resuming timescale 1 my raycast doesn't work on those spawned objects. I checked in the editor and they are there and the correct scripts are attached for correct detection. The raycast is still able to detect UI and empty space hits, but not object hits.
After I click my built in play button, which sets timescale to 1, the raycasting works fine.
I use Physics.Raycast to cast a ray on the objects.
Answer by AbandonedCrypt · Mar 04, 2021 at 07:35 AM
You're probably raycasting in FixedUpdate(), FixedUpdate() does not run during Timescale 0. Move your raycast to Update().
I'm using it in update - checked that the update loop is running but still no ray cast hit after spawning the objects. Only when I unpause briefly then it works.