Crosshair change when hovering interactive objects - a different approach from Even Tick?

Unicorn.Games
Thu, 14 Mar 2024 01:00:58 +0000
UI

Hi everyone!
I have been looking for a way to change the crosshair texture when player is close to an interactive object without having to resort to Event Tick.
I’ve heard that we should avoid Event Tick at all costs
I know I know, sometimes we have to. But it does feel a waste of resources to use Event Tick during the entire game because of crosshair… ?

I did find an alternative using the camera movement to trigger the Line Trace and then if it hits an interactive object it changes the crosshair texture. The problem with this approach is that if the player stops the camera movement the crosshair will revert to the original texture, not really what I am after.

But the same as having event tick in this case you also have Line Trace happening on every move.

FYI I really don’t know how this impacts performance - either event tick or line trace - so I am just looking for something that does not happen frequently throughout the game.

I came up with a rather odd solution (maybe not that new? hence this post): add a box collision in front of the first person camera that is of a good length and when this box is overlapped by an interactive object it changes the crosshair. When the overlap finishes it restores the crosshair to the original texture.

Here is what it looks like:

The red arrow is hidden, I used it to set up the length of my box

I check if the object has an interface, is valid and has a particular tag. Then it adds to viewport the interactive crosshair Widget when overlapping an object. Then on End Overlap it removes the widget from viewport

My question is: is this stupid? Am I using more resources this way? Trying to avoid line trace or event tick but I am using a box collision which keeps (?) checking is something has overlapped it?

Thanks heaps!

2 posts - 2 participants