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

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

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

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

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.

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

Check here:

And here:


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… ?

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?

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?


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?

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.


I’ve gotta say it now looks pretty dooky.

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

  • in the HUD class

– 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

  • player gathers data and send it to the HUD:

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

Zipped project:

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.

1 Like

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:

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

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

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.

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?

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.


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?

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

If you prefer it as is, Clear it first:

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?

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

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

(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?)

how can I check it for the screen position

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

image

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:

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.

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?

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.

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: