Scan in Radius, Get closest Actor of class, Move To and Attack

Hi, I’ve been seriously struggling with the same issue for days now and it should be fairly simple. I’m creating a top down survival game for mobile with only 2 buttons. I’m implementing a simple harvest resource/interact system (classic Destroy tree to gather wood), but I have some issues getting it to focus on the actors. I’ve been searching hundreds of tutorials but they are all using FPS and a system where you mouse at the actor you want to attack/harvest (chop tree) with a line trace. Instead I want my character to automatically move to nearest tree and harvest it.
To clarify: The Player checks in a radius around it for nearest actor which is interact-able (Resource/Enemy) and highlights it (spawn circle underneath), if the INTERACT button on screen is pressed, the Player will move to nearest actor (the one highlighted), when under a given vector length, it will set “PlayerIsHarvesting” and start animations+attacking resource (tree), which on death will give wood.
Same goes for Attack, but instead to Enemy actor and uses a separate button.
See EPIC drawing below:
Pasteboard - Uploaded Image
I have tried accomplishing this goal first by using an invisible collission sphere on my Character and use OnBeginOverlap. Couldn’t get it to work. Then I tried LineTraceByObject (Sphere). Can’t get it to work. Tried other line trace methods and even went to the horrible GetAllActors input. Still can’t get it to work, so I must admit defeat. _
Can someone please help me?
See BP script below:
Move to interactable actor posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

Thank you so much for your help, I feel like I’m getting closer and learning a lot about casting. However I have never worked with Casting or SphereTrace before. This is what I have now:

I don’t understand why I need to cast the hit back to the Interact-able Object? Isn’t the Trace there to get the hit location of the object?

How should I proceed now for him to move to the Tree and attack/interact with it? (Sorry for being so useless, I have literally just spent 6 hours reading in the documentation to try and find the solution on my own. I guess learning doesn’t come easy here).

Side note: Won’t I need to replicate this BP for every interact-able actor?

Thank you!

Jesus, I cannot thank you enough for your helps. I still havent exactly gotten the actor to move, but I think were closer. Earlier I got him to move, but to wrong location as I was using only TraceSphere - so he would hit the floor and move to that, like you said.

Here’s what I got so far, player is still not moving, despite printing string ‘HELLO’ - Am I stupid or have I just looked at this so long that my brain is mush

The reason the first branch is from false is theres something wrong with the BOOL, I tried with printstrings and it doesnt execute from True. So I temporarily moved it to false.

Thanks!

I’m almost at my goal now. I went back and redid everything in a new way. I have gotten the harvest event to work, but unfortunately only on Actor Collission (see video). So right now it starts the harvest event when my character physically touches the Harvest Actor, how can I easiest make this happen on key input.

Is it possible to Fire a SphereTrace that activates “Event OnHit”?
I tried by just adding a Key Input (when pressed) but this would no activate branch 1 on screenshot (is it because its not in my BP_PlayerCharacter?

Whats the easiest way for me to press a key and execute the first branch in the screenshot (highlighted in blue) in the other actor? :slight_smile:

My player character is called BP_PlayerCharacter and I’m trying to activate a function in BP_Harvest_Actor

I’m sooooo close now!!!

**I can’t upload video to thread or embed, so here is video link, it’s only 0.5mb **https://ufile.io/jvcjs

Something like this might get you going. Just learning this stuff myself. Good luck. If you try this on your tree_BP set an actor tag to harvest. Then add this button event to your character BP. Also make sure you setup the button input under settings for the button you want to use. From the end of these nodes continue on with the rest of yours. By using the two conditions we can essentially pick which tree to harvest when multiple trees are less than 400.