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:
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:
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.