Is trace the best way to interact with an instanced actor whose vector is known?

Lets say I have 200 instanced mesh actors randomly spawned in the world at specific locations. The player will not collide/shoot/etc these actors.

Is trace the best way to interact with them or is there something simpler and/or more efficient?

I’m not entirely sure what u want to achieve. What do you mean by interact? I assume you want to make those MeshActors clickable!

If you want them to be clickable:

  • Check that bClickEvents flag in your Controller is true
  • React to the ReceiveActorOnClicked / ReceiveActorOnReleased Events of those Actors to perform your operations/interactions.

If trace or the click events are more practical highly depends on your use case.

Have a Nice Day!

DarthB

Have you tried something like “getAllActorsofClass” ? Maybe this helps you - YouTube

I also want them clickable, but that is pretty straightforward.

I want it to be able to call an actor’s functions while only knowing the actor’s location and nothing else.

A well I think of something like an explosion now and then: (Multi) SphereTrace by Object is the way to go.

I’m assuming that UE already does something to get good efficiency by only testing those actors that are relevant (somehow) for the trace.

Or are you storing the 200 Transforms/Locations for later access?

This is a map generator. I need to be able to call a single tile and tell it to change mesh, or at least destroy itself and replace it with a new mesh.

If I can do that I can pretty much do anything else as well. Just trying to figure out the best way to interact with the tiles.

if I have 50 deserts, wouldn’t that just get all of them?

How do I single out 1 actor among many?

The below video explains the Single Line Trace. I intend to use this not just as a player, but as part of a procedural map generation process that has no player input. It may get called thousands, or even millions of times during generation, so hopefully that isn’t a problem performance-wise.

So it looks like Single Line Trace is the way to go, unless someone has a better, more efficient way to interact with an instanced actor whose only known property is a vector…

Okay your map is tile-based that means you could also reference to the actors by using a 2D Array. Like: ActorOnTile[xPos,YPos]->MyFunction();. If that is possible it should be more efficient.

Yeah that is the question, is it possible? I don’t know and that is what I am searching for.

The idea basically sounds like a point trace instead of a line trace. I have been all over blueprint and I don’t think it exists.

Basically get vector, is an actor there? Call its functions! :slight_smile:

With the line trace I have to line up the vectors, ensure nothing is in the way or exclude anything that could be in the way(my mountains for instance), do a small amount of math, etc. All small stuff by itself, but when my map generator needs to do it millions of times it adds up.

Maybe I will take this to the feedback forum and see if they can take a crack at it or add a point trace functionality.

What you want to achieve would be easily done in C++ by using:

UPROPERTY()
TArray<TArray<AActor*>> Map;
...
Map[2][3]->MyFunction();

I’m not deep enough in Blueprint to guarantee that there is a possibility to create a 2D Array in Blueprint but maybe someone else knows?

Pretty sure you can create 2D arrays, though I am not exactly sure how. Maybe just creating 2 arrays and linng up the indexes?

Couple problem though.

  1. My instanced static meshes don’t have unique ID’s.If I could figure out how to load them into an actor array with ID attached, it would be a step closer.

  2. Even if I have the ID for the tile, and know where it is, what function/event/etc in blueprint can actually call on that tile? It seems like everything involves colliding in one way or another. Even the line trace is “On hit”.

Is it cast? I know that works to blueprints and classes, but does it work on a single instanced actor that is the same as a hundred others?

2D arrays can actually be represented with a single 1D array.
Here’s how it works… you have width and height defined somewhere, then you’d create the array by multiplying these values arrayLength = width * height.
Then, you would simply follow the indexing formula (width * row) + column.
So, to set an element, you’d use array[width * row + col] = value
And to get an element you’d use value = array[width * row + col]