# 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:** 1

<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 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/1 "2021-09-15T04:01:39Z")

</div>

Hey all,

I’m a very, very novice programmer, who just wrapped up a Udemy course on C++ with Unreal. Despite that, I’m finding the Blueprints more and more easy to use, so I guess that’s that.

Anyway, I decided to go without too much direct instruction for a while and try my hand at implementing something of my own. For my first effort I settled on making a very, very rough mechanic of a movement system from this book series, Mistborn. Basically, my goals are:

1. Make it so the character can throw a coin in whatever direction they’re looking (done!)
2. Make it so the character can press a separate key and be flung in the opposite direction of the last coin they threw.

I found out that there’s a Launch Character function, which is superb, but getting the launch velocity for it is proving tricky. In my mind, the best way to get this would be to get the Vector from the most recently thrown coin to the ThirdPersonController, then use that to get a Velocity and then fling the player. But I just can’t seem to find a good way to get the location of the last coin thrown. I’d use a cast and then GetActorLocation, but I’m struggling to find a way to plug an “Other” object into the cast. The InputAction event doesn’t have that object node to plug into a cast, I don’t fully understand why that is, and I’m a bit stuck on how to progress.

So, TL;DR: how can I get the location of an object in the world on an input event to get a Vector to launch the player?

(bonus question, I’m not sure how I would specify it to only grab the location of the most recently spawned coin, so if anyone has any advice in that department please let me know thanks)

---

<div class="post-metadata">

**Author:** ![Neongho](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neongho](https://forums.unrealengine.com/u/Neongho)\
**Post date:** [September 15, 2021, 5:27am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/2 "2021-09-15T05:27:10Z")

</div>

To get the direction from 2 actors Actor.Loc - actor2.Loc then multiply then convert into unit vector then multiply it, then enjoy the launch function.

---

<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 15, 2021, 5:31am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/3 "2021-09-15T05:31:28Z")

</div>

You mean do this in C++? I can just do this .Loc thing, subtract them, and get a direction, then multiply it and convert to vector? Is there a way to do it through blueprint?

---

<div class="post-metadata">

**Author:** ![Neongho](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neongho](https://forums.unrealengine.com/u/Neongho)\
**Post date:** [September 15, 2021, 5:57am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/4 "2021-09-15T05:57:45Z")

</div>

I told you a concept, now try to apply it on blueprints.

Actor.GetAcforLocation - Actor2.GetActorLocation then multiply it.

---

<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, 5:59am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/5 "2021-09-15T05:59:37Z")

</div>

Top bit is the coin toss, bottom is the launch:

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

Script to copy:

> **[toss the coin to the ■■■■■■■ posted by anonymous | blueprintUE | PasteBin For...](https://blueprintue.com/blueprint/g-s_b3be/)**
>
> No description provided

* * *

> how can I get the location of an object in the world on an input event to get a Vector to launch the player

You could store the location only as a vector but then you’d need to wait for the coin to stop moving. So we store a reference to the spawned actor instead. One thing that’d need adding here before jumping away is to check whether last coin is valid - perhaps something scooped it up! Better safe than sorry (and coinless).

---

<div class="post-metadata">

**Author:** ![Neongho](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neongho](https://forums.unrealengine.com/u/Neongho)\
**Post date:** [September 15, 2021, 6:01am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/6 "2021-09-15T06:01:34Z")

</div>

there is multiple ways to do it, though I’ve learn’t a new one it seems that RotateVectorAroundAxis… is kind off new lol.  
But I stick to the tradiational way vector - vector …

---

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

</div>

> [@Neongho](#):
>
> vector - vector

That’d give you another vector only. But you may not be happy with said direction (after normalising) and want to modify it a bit.

---

<div class="post-metadata">

**Author:** ![Neongho](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neongho](https://forums.unrealengine.com/u/Neongho)\
**Post date:** [September 15, 2021, 6:07am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/8 "2021-09-15T06:07:33Z")

</div>

No that does give you the direction… lemme lurk my code, sorry if I did say something wrong : O

---

<div class="post-metadata">

**Author:** ![Neongho](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neongho](https://forums.unrealengine.com/u/Neongho)\
**Post date:** [September 15, 2021, 6:08am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/9 "2021-09-15T06:08:50Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/a/dad800adfbac39f19e4967ecdc717f99d410c7a7.jpeg)  
This works for me. Kicking launching a player.

---

<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 15, 2021, 6:11am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/10 "2021-09-15T06:11:24Z")

</div>

Right, I get how this works, but my question was how to even get the location of the second actor. I know how to get the vector once I have the locations, I was just confused on how to get the locations in the first place.

---

<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 15, 2021, 6:12am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/11 "2021-09-15T06:12:06Z")

</div>

Thanks so much for the help!

---

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

</div>

> [@Qaztarr](#):
>
> how to even get the location of the second actor.

Whenever something is spawned, we store a reference - it stores only the last spawned coin. There is an explanation above, too.

---

<div class="post-metadata">

**Author:** ![Neongho](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neongho](https://forums.unrealengine.com/u/Neongho)\
**Post date:** [September 15, 2021, 6:15am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/13 "2021-09-15T06:15:10Z")

</div>

Or with getAllactors you get that specific actor! L : all roads go to rome, but there is many not only 1 : P

---

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

</div>

> [@Neongho](#):
>
> getAllactors

You cannot. It does not guarantee order.

---

<div class="post-metadata">

**Author:** ![Neongho](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neongho](https://forums.unrealengine.com/u/Neongho)\
**Post date:** [September 15, 2021, 6:18am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/15 "2021-09-15T06:18:25Z")

</div>

Yes you can, just declare a variable on it with a specific value that is what is a variable on it’s core, But hey do not use my way as it is expensive and stupid… LoL

---

<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, 6:26am UTC](https://forums.unrealengine.com/t/how-to-cast-to-the-location-of-a-separate-actor-on-an-input-event/250833/16 "2021-09-15T06:26:28Z")

</div>

> [@Neongho](#):
>
> Yes you can

Agree, one can but _absolutely should not rely on GetAll to get a specific element out of an array_. Please avoid - every 10th run or so you’ll get elements in a different order and open the gate to a little debugging hell. Reference stuff.

Tis all, my 2 ¢oins ;p

---

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

</div>

So I gave this a shot and I’m still having an issue now, I can set the Last Thrown Coin but then I can’t seem to do the Get Static Mesh off of it (it just won’t show up?) previously I was getting the capsule component but that isn’t showing up either. Any idea why that might be?

EDIT: It saying “Object Reference is not compatible with Object Reference” is really throwing me for a loop

---

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

</div>

Seems like the issue is that my BP\_Coin isn’t compatible. Still a bit confused but on the right track I think

---

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

</div>

> [@Qaztarr](#):
>
> Seems like the issue is that my BP\_Coin isn’t compatible.

Right click the blue pin:

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

And promote to variable. This will create a reference variable for the correct type.

---

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

</div>

It worked! One final question, I think. Got a bit of a bug and I’m hella confused

I noticed that as I was pressing the key to launch, sometimes I was being sent in a direction completely away from where the coin was. When I pressed F8 to check it out and selected the coin, I found that the static mesh of the coin is way over there while the transform (is that the root?) is in a completely different place. I would think that because I childed the static mesh to the root component, that they would stay together, but that doesn’t seem to be the case. What’s also weird is that it seems like, despite using the static mesh in the launch, that when I press the key I’m pushing away from the root component and not the static mesh. Any idea why this could be happening?

EDIT: Figured it out! Just replaced the root component with the collision. Weird

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/6/16d6a200ea850b8cda3925893aaf7f90de2cb8ef.jpeg)

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