Check for actor at specific location

I’m creating a game that uses a grid-based tile system. Each tile contains a reference to it’s neighbours. I’m trying to create a construction script that automatically searches for neighbours to save manually linking them, but I can’t figure out how to get an actor at a specific location. Any tips?

I may be on my way to solving this. I created a function that uses a line trace to check in a specified relative location. The problem is when I return the Tile_C object, and attempt to connect it to the SET node for the appropriate variable, I get the error object ‘SKEL_Tile_C’ is not compatible with object ‘Tile_C’. But my function has a single output of type Tile_C, so I’m not sure what’s happening here?


EDIT: I’m not sure why my screenshot is being auto-resized to an unreadably small image.

Here’s an imgur upload:

Another update:

I added a “Cast to Tile” node after the function return to force the reference to the correct type (though I’m still not sure why the function isn’t returning the expected, defined return type). This casts the SKEL_Tile_C to Tile_C and seems to work.

However, I’ve got another problem in that the function isn’t executing as expected when called multiple times in the same graph.

I’ve set my Single Line Trace to draw a debug line showing the ray cast, because I wasn’t getting the expected results. I call the function in my construction script (also tested by attaching to a Begin Play event in the event graph) four times, once each for +X, -X, +Y, -Y. However inconsistently, not all function calls are executing. This error is visible both in the draw debug for the line trace, and the lack of expected results.

Okay I seem to have solved the problem, by using a Sequence node rather than chaining all of the function calls together.

I would still like to understand why my function is returning something of type SKEL_Tile_C (I don’t know what this class is) instead of the specified type Tile_C.

I hope someone can answer you because your method seems pretty interesting(coming from a guy who is also working with tile maps :slight_smile: ).

Does your line trace work for instanced meshes that have been procedurally generated? I ask because it seems like the maps I generate procedurally all act as 1 single object once generated.

I’m not sure I’m afraid. Currently I’m hand-placing tiles, but I do intend to refactor to procedural / run-time generated tile maps in the future. I’ll be sure to update this post when I do.

how about this, create your tile blueprint, make a big enough volumn that could overlap with neighbour tiles.
Create a function or interface or custom events to call during BeginPlay in level or game mode, which use getAllActorsByClass and loop through them.
Where the function would use the onOverlap to return a array of actors/components, and you can save it to a objectArray variable.

When you have procedural generation later down the road, you won’t have to worry about hooking up as well. Just generate and place tiles, and existing gamemode/level logic would still be good.

Sounds worth exploring.

The “SKEL_…” thing is definitely a bug. “SKEL_” is the prefix we throw on an intermediate class that should be kept internal. If you haven’t already, could you please post this issue on AnswerHub with repro steps (and maybe the asset files that are giving you the issue).

Thanks and sorry for the confusion!