I need help with linetrace component hit clearance

I’m trying to get the static mesh from instanced static mesh, it works completely fine but one issue.
That issue is when I’m not looking at that static mesh, it still says i’m looking at it.
And when I try to make branches like, “if static mesh I’m looking at is A, then keep doing this.” and when I’m no longer looking at it, it doesn’t stop, it only changes if I look at to a different static mesh and never goes to null.

I tried to create a null static mesh and setting my static mesh to it for every 0.5 seconds to clear it if I’m not looking but it didn’t work. I can’t set it to anything.

When I close the game, debug window says something like “Error: Static mesh accessed to null” but doesn’t set it to null" and it’s not clearing when I’m not looking at that mesh anymore.

When you’re not looking at your target component, you’re still looking at something, be that a wall or the ground or something, and Is Valid still returns True; but since the object you’re looking at cannot be cast to InstancedStaticMeshComponent, the Set node is not called; therefore its value stays the same as it was when you were looking at the object;

If you don’t want to check the component you’re looking at by its class or its tag or something else, you can use the Cast Failed output pin to set the Hit Component variable to None or whatever you need there.

I posted this question yesterday and I solved it already, somehow it wasn’t approved until now. But your answer might be useful for others.