How to get more correct raycast results or how to fix a bug I created

Hello people,

Working on my building system I encountered a bug that I’m not sure how to fix (how to implement it better). Basically my setup is this:
I have a


component inside my actor. I’ve setup all collision channels and my code working correctly and I’m getting the results I want. See picture below:

Green trace is OK - I get a hit
Red trace is OK - I don’t get a hit
Orange trace is not OK - It kind of constantly changes between hit and not hit. The problem occurs due to the fact that the object is moving (and the player with it) So at one frame it is hit, but in the next frame the object is at different position, so it kinda takes like 0.001ms to update the position to get a hit again. So it constantly goes between hit/not hit at very fast pace. For visual showcase please check between 0:16 and 0:20 Showcase Building System - YouTube

I only do a trace and nothing else specific from the code view point. Do you have any ideas how to fix that?

My solution:
One possible solution I thought of was running a trace, at the hit position spawn a sphere, get a list of all overlapped actors, check where the closest one is and return it as the hit target. But that causes another problem - I need to run a trace with specific length which might be different each time.

Anything else you can think of guys?