How to use Get all actors of class, followed by Get(a copy) to determine which copy of the actor to use

I am trying to make a point and click game, where you click on different locations in front of you to pick where to go, however, I cannot for the life of me get it to check which specific copy of an actor I am trying to interact with. The number on Get a copy changes which copy i go to, but I want to have it automatically check which copy is being interacted with.

you definitely dont wanna do it that way ha

assuming you want to potentially move to locations not just actors you’d use
gethitresultundercursor() probably on tick or timer and then you’ll have a ref to the location and hitactor at all times

if you want to use onclicked for whatever reason the have the actor tell the controller its been clicked

you should 90% of the time assume that any Array returned by a function is in a random order (if you specifically put the elements into the array in a specific order, or if it is the result of a line trace multi are the exceptions)

what GetAllActorsOfClass() does is has the World step through every actor that is registered to it, and then attempt to cast it to the selected type, and then insert them into an array to hand to you. So Array[0] could be any random actor of that type, and might not be any specific one.

if you want to test an Array that is returned for a specific element matching a specific criteria you would need to iterate over it (probably using the ForEach() node)

to get which element was clicked on there are a few different options:

  • using an InputAction for the mouse/touch to then fire a Ray projected from the Camera going through the mouse coordinate offset
  • giving each actor an OnClick() to respond to them being clicked on
  • in Tick() or a Delay-Loop see if the mouse-click/touch has occurred and then do the Ray-projection-offset method.

stepping through every actor of a type to see which one matches a criteria will be very slow, very inconsistent, and on top of everything will be very spiky in performance, so should only ever be done very sparingly especially in blueprints.