# Get Distance To shows 0.00

**URL:** <https://forums.unrealengine.com/t/get-distance-to-shows-0-00/555916>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE4, question, Blueprint\
**Created:** [May 13, 2022, 12:39am UTC](https://forums.unrealengine.com/t/get-distance-to-shows-0-00/555916 "2022-05-13T00:39:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeiDiz1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JeiDiz1](https://forums.unrealengine.com/u/JeiDiz1)\
**Post date:** [May 13, 2022, 12:39am UTC](https://forums.unrealengine.com/t/get-distance-to-shows-0-00/555916/1 "2022-05-13T00:39:41Z")

</div>

Hello everyone!

I am totally new to the Unreal Engine and the forum (it’s my first ever post!).  
I am trying to create a blueprint that will change a static mesh’s material.

In fact, I have it working, but I wanted to make it better by checking the distance between the mesh and player and allowing it to work only if the distance is lower than “X”.

I’ve found the “Get Distance To” node, but I have problems with making it work.  
This is what my blueprint looks like:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/9/d/39d28e9535fadb1084e5e4b7815c9083b6e01528.png)

How can I check the distance and Set the material only if the distance is lower than the “X”?  
(If Get Distance To Return Value \> “X” return False)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 13, 2022, 9:54am UTC](https://forums.unrealengine.com/t/get-distance-to-shows-0-00/555916/2 "2022-05-13T09:54:10Z")

</div>

I know, it doesn’t work, right? 🙂

This does, though

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/7/b87c5bfb83f116a2b345cd3ba0c925841bff4a57.png)

---

<div class="post-metadata">

**Author:** ![JeiDiz1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JeiDiz1](https://forums.unrealengine.com/u/JeiDiz1)\
**Post date:** [May 13, 2022, 10:12am UTC](https://forums.unrealengine.com/t/get-distance-to-shows-0-00/555916/3 "2022-05-13T10:12:57Z")

</div>

I managed to solve the distance problem the following way:

I created a function in my “BP\_ActionItemClick” called “GetDistanceTo”:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/e/b/6eb7aada4c2b31fcdcb45e057b3daaf20b4e27ab.png)

I called the “GetDistanceTo” function in my “BP\_ActionItemClick” like that:

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

**And it does work perfectly.**

**However** , in the beginning, I tried to create the “GetDistanceTo” function in a new actor component blueprint to make it reusable. When I created the same function (let’s call it “Get Dist” here) in a new blueprint, it looks like that:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/0/3/10362c36d0af2ffba17373bd4dbf445cda6442f0.png)

but when I import it into the “BP\_ActionItemClick”, it doesn’t work.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/2/a/42aaba31e555705e12f5878fffc7f8c21706a056.png)

It says that I have to connect something to “Target [self],” but I can’t connect anything to “Target [self]”. So what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![JeiDiz1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JeiDiz1](https://forums.unrealengine.com/u/JeiDiz1)\
**Post date:** [May 13, 2022, 3:31pm UTC](https://forums.unrealengine.com/t/get-distance-to-shows-0-00/555916/4 "2022-05-13T15:31:13Z")

</div>

How to fix this?  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/f/b8fd7bfc741f77f80c2eaa4bdff3ac86db6faa63.png)

---

<div class="post-metadata">

**Author:** ![Zikitamon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zikitamon/32/464606_2.png) [@Zikitamon](https://forums.unrealengine.com/u/Zikitamon)\
**Post date:** [May 13, 2022, 3:42pm UTC](https://forums.unrealengine.com/t/get-distance-to-shows-0-00/555916/5 "2022-05-13T15:42:20Z")

</div>

I don’t think making an Actor Component just for that function makes too much sense. The logic of getting the distance to the player and comparing that to a value is only 4 nodes as @ClockworkOcean showed, so I think you should just keep that logic inside of the Actor class.

And, the reason why you get a warning when you try to cast to BP\_GetDist, is that what you are trying to do is casting (changing the data type) the return value of GetOwner (which is Actor) to an Actor Component class. That doesn’t make sense in the same way as it wouldn’t if you tried to cast a dog to a spoon.

What you probably would want to do there is to call Get Component By Class and giving your BP\_GetDist class as the class argument.

---

<div class="post-metadata">

**Author:** ![BLOODYJAYDEN](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BLOODYJAYDEN](https://forums.unrealengine.com/u/BLOODYJAYDEN)\
**Post date:** [December 11, 2023, 1:43am UTC](https://forums.unrealengine.com/t/get-distance-to-shows-0-00/555916/6 "2023-12-11T01:43:28Z")

</div>

ty this worked and is really simple
