Alternative to GetAllActorsOfClass?

Hi there,

So I just started doing a small fast travel system, but I stumbled upon a small issue near the end. I stopped using GetAllActorsOfClass to get references a while ago, but for this specific scenario I could not find a way without using it, so I’d like to find an alternative to it.

I’m using the same blueprint on a few spots on the map, so I’m trying to find a way to get locations for each specific actor of this blueprint class in the level to be able to teleport to them.

Also, a bit unrelated but I have a variable called “NumberTag” used to put a number on each fast travel “station”. This variable would change the name of the location displayed from my “Locations” array. Since I can’t get a way to get a reference of all actors on the level, I can’t find a way to get the number assigned to them.

Thanks lads.

You can add a vector array variable, named LocArray, in NewGameInstance. Then it will restore the Arrow's world location like this:

  1. get all actors(FastTravelBP) by GetAllActorOfClass
  2. clear all locations of the LocArray
  3. visit every actor by ForEachLoop
  4. add the location into LocArray
  5. do next action by Completed of ForEachLoop

Best alternative for GetAllActorsOfClass is to keep track of actors as they are spawned. Make actor register themselves on BeginPlay to some other more global class (like GameMode) and make that class put them on array, on destroy of actor make actor call global class to unregister itself and remove from array.

Also using GetAllActorsOfClass once to make some fixed list won’t do hard or else you have too many actors

Thanks for the advice. However, I don’t see how it’s different from what I have right now, except being better optimized and futureproof. Getting all actors and adding them to an array will sort them in a specific way that might not be the one I want. Is there a way to add the location to the array to a specific index ? Right now each actor has a number and a name tied to it that I’m setting myself. If the locations are not added to the array to their assigned number, the names won’t match the locations.

Thanks for the input. I’m storing the data in a game instance as of right now so I assume it should be good ? I kind of get what you are saying but not everything, sorry. All fast travel locations are in the same level for now, so they’re all spawning at the same time (?), how would I add them to the array that way.

I understood nothing from the last sentence, sorry.

I would recommand you to change your approach a little bit. For once use your FastTravelBP Nodes more as a Data Holder I usually name them Markers. They hold a bit of Information about themself like a Name, Explored or not and usually some info where they lead to like LevelName and TargetMarkerName (where to teleport to basicly). I use different types of Markers like SimpleTeleport, LevelTravel, etc. only data changes a bit but no functionality asside from a couple calls to my Manager (explained later)

As for the GameInstance I just store necessary Data I need to persist between Levels. In my case only the TargetMarkerName since that is the only thing I need to lookup to know where to teleport to if I came from a different Level. I use a Save File in addition since I store things like Explored Fast Travel Points.

The last thing is you want the Interactive Stuff and Management happen in a separate BP. For me I choose a simple Manager class that I drop into each Level. You can expose a Array of your Markers and Assign them in any order you like (aslong as they are placed in the level) So you dont need to have a NumberTag to keep track of :stuck_out_tongue_winking_eye: just look at the Array index and you are good to go. All the other Stuff like UI and Interactions are located there and are reused. For Simple Teleports I dont bother to Hand assign them I use getAllActorsOfClass once on begin Play.

I got more Complex things going on but thats it in the simplest form and you can use it for more than Fast Travel as for me I Manage all kinds of Markers there like NPC Travel Routes. But thats another Story :stuck_out_tongue_winking_eye:

Good Luck and let me know if you did not understand something.