Hello Everyone,
I am using First Person Blueprint… I have created 3 actor classes: Actor 1 (Cube), Actor 2 (Sphere) & Actor 3 (Cone)
My goal is to add Radial Trace over Actor 1 such that it moves towards Actor 2 once detected. I managed to enable Actor A to detect Actor B.
However, I noticed that Actor 2 name appears 3 times on the play mode because 3 lines of trace cross Actor 2 as can be seen below. How to edit my code such that it types the name only once as long as its the same Actor instance?
Also, I used simple move to Actor and set actor location to move Actor 2 to Actor 1 but none of them seem to be working as expected with me. Also, I ignored Actor 3 in the array but still its name does appear. No idea what mistake I did while coding this but how to let Actor 1 moves towards Actor 2 when the trace hits it and how to ignore actor 3 in the trace area using ignore actor array?
Code - part 1
Code - part 2
Code - part 3
Also what changes that I have to do to move this work to the Third Person Blueprint?
Okay, you are asking a lot of questions here so let’s break it down one by one.
**How to edit my code such that it types the name only once as long as its the same Actor instance? **
One way to do this is you can have an array of “already hit” actors that gets repopulated every time you do to a radial cast and when you go to print out the name of the hit actor in the for loop, you check if that actor has already been hit, and if it hasn’t then you print it out.
No idea what mistake I did while coding this but how to let Actor 1 moves towards Actor 2 when the trace hits it?
In the “Set Actor Location” node, target should be the actor you are moving, and new location should be where you are moving it to. It looks like you have them reversed, and are moving Actor 1 to the location of Actor 2.
how to ignore actor 3 in the trace area using ignore actor array?
I’m actually not sure why this isn’t working. I would try doing a “Trace by channel” instead of “Trace by object” and then just changing to collision parameters on Actor 3 so that they are not hit by the trace.
Also what changes that I have to do to move this work to the Third Person Blueprint?
I don’t believe you’ll need to make any. It should work the way you have it set up, since nothing you are doing really uses the character at all.
If the only purpose of the traces is to detect if actor 2 is in inside the attraction radius, I think you’re better off giving actor 1 a collision sphere (for the radius) and then use detect overlap events. On EventOverlap cast the overlapping actor result to Actor 2 to make sure its the right target. Then you can get the target’s world position and start moving Actor 1 towards it.
+Fotosynthesis can you clarify more? with a graph maybe
This would be a way to get a similar result using overlap events. It all depends what you want to do with it though. And if you are looking for a more natural attraction you may want to use force instead of setlocation.
Thank you +Fotosynthesis… I did exactly the same as the images but Actor 1 didn’t move towards Actor 2 still…
The string doesn’t even print to say I can detect Actor 2
Also I didn’t get the force thing…
How is the output of your copy?
Thanks a lot
Oh if you do add the extra bit to the EventTick, make sure you check “Start with tick enabled” in the class defaults. (this doesn’t need to be checked if you don’t use the extra bit)
If you press play while actor 2 is already inside the radius of actor 1, it won’t do anything. You will need an initial overlap event before actor 1 realizes actor 2 is inside its radius. If you do need this behaviour, you could add a bit to the BeginPlay in the eventgraph to make it work in that situation too (see image).
With the force thing I meant that instead of using a SetActorLocation node to move Actor 1, you may want to use the AddForce node instead, to push it towards Actor 2 using a physical force. In that case you will need to get the vector from actor 1 to actor 2 and apply force in that direction. But this all depends what you want to do with it. I would recommend you just get it working first using SetActorLocation.
+Fotosynthesis
the link from “get” to set target doesn’t connect (see image)
before play
output is
Change the variable type for Target to just a generic Actor Reference

Or Add a cast node before you set the variable:
+Fotosynthesis
That worked perfectly now
Thanks a lot
+Fotosynthesis
Now I would like to learn about Add Node… How is it different from set location?
This solution worked with me… really thank you so much +Fotosynthesis
No problem! Good luck with your project!