Download

About TArray<> and actors

Hi, is it a good idea to create a struct containing in a TArray<> all the actors you will interact in the current level? So, there will be no search at runtime but access directly to TArray to get an actor?

thanks

In your case what would happen in the world requiring you to lookup your actor in the TArray?
Collision would be a better way to interact since you’ll have access to the actor you collide with directly.

It depends.

If your game is a large open world with tons of types of actors, then it’s going to be pretty nasty to search that list (rather than a collision query or some such).

If your game has small discrete areas with a small number of actors, then having a list of those actors (such as enemies, or whatever) may make sense for quick access to various gameplay systems.

Yeah. in my case i want to store some actors (less than 20) that Will be very important for gameplay… for instance, i have a switch to set light turn on, this switch has a trigger that is overlapped…
so the light object Will be stored in the TArray, when i enter the trigger, i can call the stored light and use it…

Thanks…

what use would having a list of a bunch of independent objects be? Find what you need at startup, in the locations you need it, and use them when you need it. I mean assuming your less than 20 actors aren’t all triggered by the overlap trigger, and have independent uses.

For things that are dynamically spawned and not available during load time. For example, your players open a door, which you then spawn a bunch of randomized enemies. It makes sense to store those in some easily accessible array as you spawn them rather than doing an ActorIterator or query.

sure, but that doesn’t really make sense for a bunch of stuff that is already in the level, and just needs to point at each other. store some variables with the right pointers in the right things, and you shouldn’t need to have a master array of whatever unrelated stuff.