linetrace or overlap event (which is better?)

Hello, guys.
I understand that for many of you it will be silly or simple question, but I asked anyway:)
What do you use (or maybe what used for game developing) to interact with objects: linetrace (or another trace) or overlap event?
As Im understand: the linetrace depend on "event tick", and it will negativly affect to game FPS (correct me if im wrong);
but for the overlap event I need to create collision for all objetcs that i need (and it can be many-many objects).
So, what will be lighter for the engine and what do you use in your tasks?

It seems to me that line trace would be more effecient than overlap since a line trace only happens on the frame it is cast. Where overlap needs to be checked every frame.

Line trace is not dependent on tick. For shooting you would only cast a line trace when the user fires the weapon. To detect what the user is looking at you can cast a line trace ever 0.1f seconds or so.

You are going to end up using both for different needs. I use line traces for weapons firing and interacting with usable objects in the world. But I also use Overlap events for things like health pick-ups and triggering cutscenes.

Any function that you call yourself (“run this query against the world”) will be less efficient than a callback you get from the physics system itself.
So, overlap events happen because the physics system, when doing work it would typically already do anyway, detects the overlap. This is fairly cheap.
If you, inside Tick, call “trace this line” or “test this sphere” or whatever, that’s calling back into the physics system, asking it to do more work.

Now, for things you do when the user does something – find a trace to the target for a fired bullet; find the right place to drop an item out of inventory; or similar; the difference won’t matter, and you should use the method that seems to give you the best results (objects goes to the best place.)
For things you really want tested every frame, you’re typically better off with overlap events.

5 Likes

thanks a lot man, you directed me

I know this is an old topic but I was just asking myself this question this morning. I have used several “Interact” methods in up to this point and was wondering which one was more efficient as well as easier to implement.

While both work and are fairly easy to implement, I found the Line Trace method to be my preference. It can be triggered at the push of a key. The only problem I find with this method is that in most scenarios where you can interact with an actor in your environment, there is usually a visual queue such as “Press [E] to Interact” would flash on the screen when you are close to an object that can be interacted with.

In order for this to happen, the overlap method seems to be the easier to program although can also be done with the Line trace method.

Whichever one you choose, just make sure not to make “hard references” in this kind of system. Use Blueprint Interface!