# Event tick hooked to a line trace and only one "cast to actor" node make my fps fall slowly to unplayable. Is there any alternative to fix this ?

**URL:** <https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [March 7, 2024, 12:07pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725 "2024-03-07T12:07:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![catz111](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/catz111/32/618520_2.png) [@catz111](https://forums.unrealengine.com/u/catz111)\
**Post date:** [March 7, 2024, 12:07pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/1 "2024-03-07T12:07:36Z")

</div>

Hi

I have this line trace on event tick.

 ![bandicam 2024-03-07 12-59-49-378](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/d/d/4dd72c9d4d7a12601e257697910a6277144d7b2c.png)

My fps go down with time if i have it this way. For example i start with 90 fps and it takes around 5 min to dip down to 80 another 5 min and im at 70 fps and so on. Is this not how line trace should work (connected to tick event) or is the “cast to…” node making this issue when connected to tick event ?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 7, 2024, 12:23pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/2 "2024-03-07T12:23:41Z")

</div>

So… you’re saying that if you disconnect this Tick, the performance drop goes away? Do you have any errors / warnings in the log?

---

<div class="post-metadata">

**Author:** ![catz111](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/catz111/32/618520_2.png) [@catz111](https://forums.unrealengine.com/u/catz111)\
**Post date:** [March 7, 2024, 12:28pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/3 "2024-03-07T12:28:53Z")

</div>

Yes i tested it without the cast to node and performance stay constant around 90 fps

 ![bandicam 2024-03-07 13-25-51-834](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/0/0/f008f465fa87a299cb3b18a3962c85fcb0467ba7.png)

But i need the cast to node im not sure how to make this work without. I try to replace it with “get actor of class” but rest of my code is not working ☹ I have some billboard widget which show up when aiming at some minion and hide when not aiming at it.

Then there is down there more code drawing more info from this same line trace if i aim at the minion or not. So far not sure how to make it to work without the cast to node

 ![bandicam 2024-03-07 13-31-22-904](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/d/a/fda16be64e070e958845a33c194706f59c926424.png)

---

<div class="post-metadata">

**Author:** ![Ari\_Epic](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ari_epic/32/956630_2.png) [@Ari\_Epic](https://forums.unrealengine.com/u/Ari_Epic)\
**Post date:** [March 7, 2024, 12:32pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/4 "2024-03-07T12:32:43Z")

</div>

That cast shouldn’t affect the frame performance, I don’t see anything in that function that I would consider weird. I think the problem is somewhere else.

You need to profile the game to see just what is actually costing the frame time. I recommend checking out [Maximizing Your Game’s Performance in Unreal Engine | Unreal Fest 2022](https://www.youtube.com/watch?v=GuIav71867E) if you don’t have experience profiling in Unreal Engine.

---

<div class="post-metadata">

**Author:** ![catz111](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/catz111/32/618520_2.png) [@catz111](https://forums.unrealengine.com/u/catz111)\
**Post date:** [March 7, 2024, 12:35pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/5 "2024-03-07T12:35:18Z")

</div>

But why would my fps slowly go down with the cast to node and stay constant if i disconnect it ? I can make a video in real time and you can see the fps drop with cast to node vs no performance issues when its disconnected

thx for the video tough i will check it out

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 7, 2024, 12:38pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/6 "2024-03-07T12:38:45Z")

</div>

There are some strange things going on:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/2/0/220fafe63083115fc9e830955d73d786b7f797c5.jpeg)

Even though you do have a reference variable. Looks like you do it often, accessing data pins from non-exec branches. Unsafe, potentially catastrophic.

* * *

The cast is not to blame here. But you can use an interface instead. I’d look for issues elsewhere. You did not answer about log warning / errors.

---

<div class="post-metadata">

**Author:** ![catz111](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/catz111/32/618520_2.png) [@catz111](https://forums.unrealengine.com/u/catz111)\
**Post date:** [March 7, 2024, 12:41pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/7 "2024-03-07T12:41:48Z")

</div>

True i forget that…

There are errors

 ![bandicam 2024-03-07 13-40-34-824](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/2/f/62f65f873ba032ccf550959d4afbc66dc01ce1ca.png)

it sends me to this then

 ![bandicam 2024-03-07 13-41-03-700](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/d/e/3deb6952158c7d89d24cc0dc512d015f6a579e55.png)

I will try replace the mesh variable you marked and test again

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 7, 2024, 12:42pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/8 "2024-03-07T12:42:29Z")

</div>

> Unsafe, potentially catastrophic.

Yeah, that’s your slowdown. It’s the log error spam. 😃

---

<div class="post-metadata">

**Author:** ![catz111](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/catz111/32/618520_2.png) [@catz111](https://forums.unrealengine.com/u/catz111)\
**Post date:** [March 7, 2024, 12:44pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/9 "2024-03-07T12:44:00Z")

</div>

Ok so priority number one is to fix all those ?

I have other access none errors i tought that wouldn’t matter that much scince logic is working ?

What if the code is working and would this log events not matter after packaging the game ? If the log error spam dissapier would that not mean that in the packaged game performance should be then better ?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 7, 2024, 12:53pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/10 "2024-03-07T12:53:54Z")

</div>

You reference stuff for a reason:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/2/7d250c97de9530d2374136b34a5d0c35bd338c14.png)

Use the `Validated Get` variable elsewhere in your script so you do not need to have wires snaking all over the place.

* * *

And if you need to access the pawn **elsewhere**. Do the cast **elsewhere**. Do not reuse pins from other exec branches unless it’s a SET node whose right hand side pin acts as a GET.

- this is not OK:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/a/1/fa199d351ed7468ae05c02adbb641b54eccbc43a.png)

- this _may_ be acceptable:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/8/1/981202848d8d2baeac5986dea6900fb85d44816e.png)

- ideally you would:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/0/7/c072789e70d3ea689c87d1f2cba81fa4d1bdd7fc.png)

* * *

> i tought that wouldn’t matter that much scince logic is working

I’ll admit that I do not understand what the script is supposed be doing.

---

<div class="post-metadata">

**Author:** ![catz111](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/catz111/32/618520_2.png) [@catz111](https://forums.unrealengine.com/u/catz111)\
**Post date:** [March 7, 2024, 1:39pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/11 "2024-03-07T13:39:15Z")

</div>

> [@Everynone](#):
>
> I’ll admit that I do not understand what the script is supposed be doing.

Basicly i can spawn a minion and he has a billboard widget showing up on him when i aim at him. Billboard works here really good so i can see him in the distance that i aimed at him. Normal widget wouldn’t work for this (or so i think maybe im wrong). So when aiming at him i can give him commands. Awso we are linked togheter with some energy beam where it fires awso on event tick and it changes it colors when i do curtain commands. For example life transfer by aiming at him and only then i can press and hold a key to sacrifice life from the player character and give it to him.. Anyway stuff like this and it all works now pretty flawless. Except this performance issues..

Thx for all those examples i will dig more into this and see where i can optimize the code.

 ![bandicam 2024-03-07 14-41-17-717](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/e/e/4ee06238e3eb95cb3332500fb20eb97cf0ac2e61.jpeg)

 ![bandicam 2024-03-07 14-41-57-123](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/f/b/ffb00116234e0956064ee7e22f26040c16608c17.jpeg)  
 ![bandicam 2024-03-07 14-42-26-223](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/b/4/9b4cf762767a98250816fda32e5b9020cb6c2ea9.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 7, 2024, 1:44pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/12 "2024-03-07T13:44:44Z")

</div>

> [@catz111](#):
>
> Normal widget wouldn’t work for this

This part does not matter, it can be made with anything. Here’s an example and a project with this (slightly more advanced) behaviour:

> [@Third person crosshair object highlight troubles](https://forums.unrealengine.com/t/third-person-crosshair-object-highlight-troubles/252041/13):
>
> The communication in the example revolves around Inheritance + Interface - a potent combo, imho. the base class implements the interface (which children inherit) the widget uses the same interface - calls children receive can be propagated: Actor → Widget Component → Widget without casting or finding user widgets (this can be done in many ways, though) the player has a collision sphere and sends an interface call to overlapped actors as we approach: [image] [image] Above, handl…

An Interface may be preferable if you want to interact with unrelated classes.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 7, 2024, 1:48pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/13 "2024-03-07T13:48:54Z")

</div>

> [@Everynone](#):
>
> I’ll admit that I do not understand what the script is supposed be doing.

What I really meant was this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/1/b8102fb4170765d7c6dccdc8a61fcde1d57a1817.jpeg)

You’re comparing whether the Hit Actor is the Hit Actor.

---

<div class="post-metadata">

**Author:** ![catz111](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/catz111/32/618520_2.png) [@catz111](https://forums.unrealengine.com/u/catz111)\
**Post date:** [March 7, 2024, 1:50pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/14 "2024-03-07T13:50:08Z")

</div>

> [@Everynone](#):
>
> An Interface may be preferable if you want to interact with unrelated classes.

I do have interafece for the health bar over him lol and i even remember the post from above that you linked. I think i made this health bar widget from it long ago on all my enemies.. Maybe i should move this minion command Icon widget there as well thats acctually a good idea but the helath widget that i have is awso made with an interface and show up on collision overlap but i need to aim at it pretty much like on the example video

> [@Everynone](#):
>
> You’re comparing whether the Hit Actor is the Hit Actor.

Yeah i want to get if the hit actor is hitting him then show this billboard widget if is not him do not show it. Same is with the commands that i want to give to him only if i hit him with the line trace. This is the way to do it no ?

Only like this all my logic works without it nothing works.

Here is where i use it on other places (i dont think hit actor=hit actor random or so but hit actor = to minion actor then the widget show up when aiming or not. I missread. I think you wanted to know this so it counts as line trace hit actor = to my minion actor as it seems else the first logic wouldn’t work with showing the widget when i aim at the minion)

 ![bandicam 2024-03-07 14-54-56-681](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/9/8/79822d93a5e2604455d5e75304aea871d7146bf7.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 7, 2024, 2:02pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/15 "2024-03-07T14:02:52Z")

</div>

The entire commented logic for this behaviour if we’re using casting:

> [@Moving an object by pointing another object at it](https://forums.unrealengine.com/t/moving-an-object-by-pointing-another-object-at-it/1657869/2):
>
> See if this point_down helps with this point_up_2 particular bit. a standard forward camera trace: You’d use an interface or inheritance if there are more types to handle, ofc. not sure how you want stuff to move, here it’s via a timeline: which results in: the branches in the script prevent it from spamming since we’re tracing on Tick: Hopefully you can adapt it to your needs. It’s a setup similar to this one:

In the Minion, instead of triggering the timeline, the custom event would show / hide its widget / billboard.

---

<div class="post-metadata">

**Author:** ![catz111](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/catz111/32/618520_2.png) [@catz111](https://forums.unrealengine.com/u/catz111)\
**Post date:** [March 7, 2024, 5:24pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/16 "2024-03-07T17:24:55Z")

</div>

I made something out of this last post and it seems to work fine. The performance issue is still there tough. I tested it around 1 hour long on improving the code then just chill for 5-10 min and stare at the fps drop. So far it seems with this code that i’m losing around 1 fps each 30 sec so in 10 min i drop around 20 fps less. I tested this without the event tick at all and performance is stable no fps drops after 10 min of waiting and watching fps…

This is how it looks like now and i made it work (kinda not exact same from above). If this saves some extra performance then was worth for sure.

 ![bandicam 2024-03-07 18-21-01-108](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/8/d/98d9978053e10b6a18cad7abc7b8e73eeecc17b4.png)

I guess it must be the errors and the log files created as you say. So i will mark this as solved where you mentioned it. Ty for the help tough lot of new stuff to learn here…

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 7, 2024, 6:11pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/17 "2024-03-07T18:11:19Z")

</div>

This is will crash & burn at some point once accessed and evaluated in another execution chain:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/d/0fd1a1b4b7387d05d881424f609fce67aee3cff0.jpeg)

If you need this data **elsewhere** , do the trace **there** to obtain it. Or store a ref to the hit actor and use it after checking its validity. Tracing is very cheap, casting is more than OK and Tick is necessary. What’s expensive is using it incorrectly.

---

<div class="post-metadata">

**Author:** ![catz111](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/catz111/32/618520_2.png) [@catz111](https://forums.unrealengine.com/u/catz111)\
**Post date:** [March 7, 2024, 6:13pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/18 "2024-03-07T18:13:22Z")

</div>

> [@Everynone](#):
>
> If you need this data elsewhere, do the trace there to obtain it. Or store a ref to the hit actor and use it elsewhere after checking its validity.

ok i will try that

It just came to my mind is it any good idea to disable the error logs (completely disable log files or so ) ? Or maybe at least disable them to test if this really is the performance bottleneck when i have that many errors ?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 7, 2024, 6:15pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/19 "2024-03-07T18:15:22Z")

</div>

I’d work on fixing the errors.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [April 6, 2024, 6:15pm UTC](https://forums.unrealengine.com/t/event-tick-hooked-to-a-line-trace-and-only-one-cast-to-actor-node-make-my-fps-fall-slowly-to-unplayable-is-there-any-alternative-to-fix-this/1735725/20 "2024-04-06T18:15:57Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
