# How to cast to the location of a separate Actor on an input event?

**URL:** <https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [September 15, 2021, 4:01am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833 "2021-09-15T04:01:39Z")\
**Posts on this page:** 20\
**Page:** 2

<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:** [September 15, 2021, 8:58pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/21 "2021-09-15T20:58:20Z")

</div>

> [@Qaztarr](#):
>
> Just replaced the root component with the collision. Weird

Aye. This is often critical when you simulate physics. Think about it:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/2/82689d445746be40ed931e17859bb7c45bab5de2.jpeg)

If you apply an impulse, the box would fly away but it moved in the relative space of that actor. When you now ask the engine where that actor is - it’s still where the arrow is pointing. It did not move from where it was spawned.

But if you make the box the root - as you did - now the whole actor is tumbling away and its world location is the same as the location of the box. Technically, you could do this instead:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/3/83cf7eb8ca6843cb07df3d12c7b4cc1455636cb1.png)

But if 1 coin = 1 actor, making the root the simulating element makes perfect sense.

---

<div class="post-metadata">

**Author:** ![Qaztarr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qaztarr/32/88717_2.png) [@Qaztarr](https://forums.unrealengine.com/u/Qaztarr)\
**Post date:** [September 16, 2021, 6:03pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/22 "2021-09-16T18:03:00Z")

</div>

Thanks again for all the help!

One final thing, I decided to draw a debug line constantly to the Last Coin Thrown, as having a line between the player and the coin (or an arrow really) is super helpful for using the system.

Is there any way to draw a debug-like arrow that will actually show up when the game is moved outside of the editor? From what I can see, debug lines only show in the editor when playing.

---

<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:** [September 16, 2021, 6:16pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/23 "2021-09-16T18:16:29Z")

</div>

Spline + Spline Mesh Component. Or ribbon particle (orwhatshername) in Niagara.

Check here:

> [@Connect mesh between two world vectors at runtime?](https://forums.unrealengine.com/t/connect-mesh-between-two-world-vectors-at-runtime/213028/2):
>
> Spline mesh component can deform meshes. Or are you actively trying to avoid using a spline? As in: This is using a cube as the beam mesh, scaled down. Would that work?

And here:

> [@Laser beam that locks and follows a target](https://forums.unrealengine.com/t/laser-beam-that-locks-and-follows-a-target/227735/3):
>
> I would suggest getting into Niagara. This channel helped me a lot Also here for the initial beam setup Then for the follow mechanics you use need to make a user parameter for the beam end variable so you can manipulate it from a blueprint Video is in french but you can turn the sound of and follow it anyway. [[Niagara : How to create electric arcs between 2 points - UE4 tutorials] ](https://www.youtube.com/watch?v=SajyFZ35OBI)

* * *

You can also draw lines with widgets, and the HUD class does it well, too. Plenty of options, actually. Even the materials can draw 2d / 3d splines - but there’s an upfront cost to setting it up.

* * *

> outside of the editor

So a shipped product or… ?

---

<div class="post-metadata">

**Author:** ![Qaztarr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qaztarr/32/88717_2.png) [@Qaztarr](https://forums.unrealengine.com/u/Qaztarr)\
**Post date:** [September 19, 2021, 8:12pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/24 "2021-09-19T20:12:16Z")

</div>

Trying to do that spline mesh thing, looked at your explanation on the first thread there. Tried to get it to work with what I’m doing but when I hit play nothing shows. What am I doing wrong?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/8/7804ec7cca1f06f445c0614662376e337e7b7da4.png)

EDIT: Hmm okay so actually I just was drawing the spline mesh too small, but I’ve gotta say it now looks pretty dooky. How should I go about making the spline mesh around the same size and color and such as the debug line?

---

<div class="post-metadata">

**Author:** ![Qaztarr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qaztarr/32/88717_2.png) [@Qaztarr](https://forums.unrealengine.com/u/Qaztarr)\
**Post date:** [September 19, 2021, 8:25pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/25 "2021-09-19T20:25:24Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/6/1/610c1c4fc051cae24f93a427bd2f317b626d2bd6.jpeg)  
Something about this doesn’t look exactly right lol I can get the shape looking nicer but the main issue is that the spline doesn’t actually begin at the player and end at the coin, it seems just slightly offset from them both?

---

<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:** [September 20, 2021, 8:00am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/26 "2021-09-20T08:00:18Z")

</div>

The coin lives in world space but the spline is set to Local. Explore the rest of the thread I linked, it addresses this very issue - the one with the red laser.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/7/b726936f13c7e036e56953fae1b003e188b1a4c4.jpeg)

* * *

> I’ve gotta say it now looks pretty dooky.

But perhaps simple lines are needed instead, draw it with the HUD:

- in the [HUD](https://docs.unrealengine.com/4.27/en-US/Resources/ContentExamples/Blueprints_HUD/1_1/?) class

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/f/1f5131c6ac28780a1d35e740e39f479ac9d3e1c1.jpeg)

– send HUD an array of points and player screen position  
– during HUD update, draw those lines and an icons  
– draw an icon on each target  
– _there are more draw options, explore_

- [blueprint interface](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/Blueprints/UserGuide/Types/Interface/UsingInterfaces/) the HUD class implements:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/c/dca4a48020af115842c29219b05e234a36379080.png)

- player gathers data and send it to the HUD:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/7/7775b0d8a33aa68c2af0e50f9f2fa5e17f2e5d3b.jpeg)

– the above finds all coins within the radius of the sphere, result:

Zipped project:

> **[linesandcoins.zip](https://drive.google.com/file/d/1CdkQgvGiSDaquO7AH-Z3fPnWuC_SGMxM/view?usp=sharing)**
>
> Google Drive file.

Have a look and test it out - see if you can get the line to look the way you need. Sadly, these are aliased. For anti-aliased, you could use widget’s _onPaint_ - create a full screen canvas and have the widget connect the points.

---

<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:** [September 20, 2021, 9:23am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/27 "2021-09-20T09:23:14Z")

</div>

In case there was doubt regarding how to do it with widgets, the project linked above has been updated and you can switch between the 2 - see what fits you best:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/4/d4de6e98c1819b435bf9bf18bc717d60b8d83d8f.jpeg)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/a/8a7ac4cb852ec1475dd4ce3fb0984d490754bdb3.jpeg)

Above, the antii-aliased lines look superior, ofc. A neat trick is to draw 2 lines, one on top of the other; the 1st one is thick and the 2nd one is thin:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/c/4/c4fa289de91e5f751a7212168e4a8817e3e01ad4.jpeg)

If you make the inner, 2nd line brighter, the whole thing will have more body / volume.

---

<div class="post-metadata">

**Author:** ![Qaztarr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qaztarr/32/88717_2.png) [@Qaztarr](https://forums.unrealengine.com/u/Qaztarr)\
**Post date:** [September 21, 2021, 7:34pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/28 "2021-09-21T19:34:46Z")

</div>

Hey thanks again for all the help, spent some time implementing the stuff you wrote out there and run into a couple things. The main issue is that when I hit play, there are lots of lines being drawn that never disappear off of the screen.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/1/41a19499f88179fd652ae59903c1cb4a3729cd0b.jpeg)

This may be related: I tried to pass in Last Thrown Coin and Last Thrown Spike (another item the player can throw that acts similarly to the coin) through making them into an array and then passing them in where in your code you passed in the array of overlapping actors. Is there a reason why doing it this way might be causing the everlasting lines?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/7/f72cd4a8e18c2b4e94bc6c26f09075d7603b9b62.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:** [September 21, 2021, 8:49pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/29 "2021-09-21T20:49:03Z")

</div>

Can you show how you add the widget and actually draw the lines? At a glance it looks like the array is not being cleared or too many widgets are added.

---

<div class="post-metadata">

**Author:** ![Qaztarr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qaztarr/32/88717_2.png) [@Qaztarr](https://forums.unrealengine.com/u/Qaztarr)\
**Post date:** [September 21, 2021, 8:58pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/30 "2021-09-21T20:58:51Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/2/b27f4b6007d56fb4854ac09ae47c2fa7c136a5bc.png)  
here’s the find line targets for widget function, to be honest I copied it directly cause I don’t fully understand how it works, do I need to tweak some stuff here to make it work with my system?

---

<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:** [September 21, 2021, 9:06pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/31 "2021-09-21T21:06:50Z")

</div>

Ah, I see. In my example the Array is a `local` variable. So either turn it local or clear it.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/b/4b9adfea78fc0ff272096bf5d960ec733cd4b9a2.png)

If you prefer it as is, Clear it first:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/e/f/effbb9f26d3e485a646a06a984445ccc81d43c13.png)

---

<div class="post-metadata">

**Author:** ![Qaztarr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qaztarr/32/88717_2.png) [@Qaztarr](https://forums.unrealengine.com/u/Qaztarr)\
**Post date:** [September 21, 2021, 9:18pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/32 "2021-09-21T21:18:18Z")

</div>

Sweet! That fixed the too-many-lines issue, but now I’m getting the issue of it just being very spazzy and weird when I move the player character around. From what I can tell it’s because I’m using a first person camera rather than a third person camera, which means the lines are drawn to the top-right of the screen whenever I’m not looking down at myself. Any quick fix for that maybe?

---

<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:** [September 21, 2021, 9:57pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/33 "2021-09-21T21:57:01Z")

</div>

> I’m not looking down at myself.

Hard to tell precisely without observing what is going on or knowing what else is needed. If I were to guess, I’d say this probably happens when the coin is not on the screen. Can you confirm? Or perhaps there is no coin to draw to line towards?

Is there a warning / error perhaps?

Btw. If you’re ever only need a single line, this can be probably simplified greatly.

A quick fix:

- check if the Coin is valid
- check if its returned screen position is valid
- if any of the above fails, don’t draw the line

---

<div class="post-metadata">

**Author:** ![Qaztarr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qaztarr/32/88717_2.png) [@Qaztarr](https://forums.unrealengine.com/u/Qaztarr)\
**Post date:** [September 21, 2021, 10:17pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/34 "2021-09-21T22:17:33Z")

</div>

Got it to not draw if the coin’s aren’t valid using IsValid, how can I check it for the screen position?

---

<div class="post-metadata">

**Author:** ![Qaztarr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qaztarr/32/88717_2.png) [@Qaztarr](https://forums.unrealengine.com/u/Qaztarr)\
**Post date:** [September 21, 2021, 10:22pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/35 "2021-09-21T22:22:45Z")

</div>

(actually slight difference, got it to draw only if either the coin or the spikes are valid when in reality I want it to only draw the coin line if the coin is valid and only draw the spike line if the spike is valid, is there any easy way to split this up or do I need a separate line drawing function for each?)

---

<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:** [September 22, 2021, 6:37am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/36 "2021-09-22T06:37:42Z")

</div>

> how can I check it for the screen position

The node spits it out the position but it also returns a boolean:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/3/c/3c6b7b90a92606820dce368b9351e71db5631b6e.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:** [September 22, 2021, 6:40am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/37 "2021-09-22T06:40:48Z")

</div>

> [@Qaztarr](#):
>
> draw the coin line if the coin is valid and only draw the spike line if the spike is valid

Not sure what _spike_ is but if it’s another actor, once you have its reference you could check isValid for it as well.

If the line is supposed to be drawn between the two, and only once both appear on the screen, it would be closer to this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/e/8ea0ab2818e090bff781f0d1228bca122e1c58a8.jpeg)

Do note that the widget may have previous / stale data. Sending a flag (shouldDraw [F]) could be used to clear that data and prevent drawing from happening.

---

<div class="post-metadata">

**Author:** ![Qaztarr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qaztarr/32/88717_2.png) [@Qaztarr](https://forums.unrealengine.com/u/Qaztarr)\
**Post date:** [September 22, 2021, 8:37pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/38 "2021-09-22T20:37:04Z")

</div>

Awesome, so I’ve got it mostly working now.

Two issues, one of which may be unsolvable

1. I want it to draw the line to the coin even when the coin isn’t on the screen. I’m guessing though that because this is using the HUD that’s not really possible, as whenever the coin isn’t on the screen the engine won’t have any way of determining where to draw the line to right?

2. The line from the coin is being drawn properly, but when I start moving (and especially when I’m moving rapidly) the line shifts from side to side and front to back (while the DrawDebugLine seems to stay firmly gripped to my player as it moves). Since both systems are using GetActorLocation, what’s the issue?

---

<div class="post-metadata">

**Author:** ![Qaztarr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qaztarr/32/88717_2.png) [@Qaztarr](https://forums.unrealengine.com/u/Qaztarr)\
**Post date:** [September 22, 2021, 8:38pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/39 "2021-09-22T20:38:55Z")

</div>

Also yeah basically the spike is just another coin and I’m checking for the IsValid on the spike as well but currently it’s “if either the spike or the coin is valid, draw the lines” which doesn’t work if it’s the beginning of the level and I throw one coin but haven’t thrown a spike yet. I’d rather it be “if the coin is valid draw the line to the coin, if the spike is valid draw the line to the spike” but I’m not sure how to do that under a single function.

---

<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:** [September 22, 2021, 10:35pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/40 "2021-09-22T22:35:07Z")

</div>

> [@Qaztarr](#):
>
> I want it to draw the line to the coin even when the coin isn’t on the screen. I’m guessing though that because this is using the HUD that’s not really possible, as whenever the coin isn’t on the screen the engine won’t have any way of determining where to draw the line to right?

You’d need to devise a system that draws a line to the edge of the screen only even though the target is further away. Usually an object behind you means a line going to the bottom of the screen.

Do note that if you were to use splines for this, they wouldn’t care as they’re actually in world space.

> when I start moving (and especially when I’m moving rapidly) the line shifts from side to side and front to back (while the DrawDebugLine seems to stay firmly gripped to my player as it moves). Since both systems are using GetActorLocation, what’s the issue?

This is _probably_ due to the Tick group. Try those:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/5/55f99f2d698fb7bbc5c449b4529c52c8dc599326.png)

[Previous page](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833.md?page=1)

[Next page](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833.md?page=3)
