I’m trying to learn how to use the Paper2D tile map, specifically for an isometric game. I would like to be able to click/mouse over on a tile and have it respond by changing something based on the intersecting X/Y tile index. However, I’m finding that no matter what I do, I can’t get any mouse events to trigger. ActorBeginCursorOver and ActorOnClick do nothing. However, these events do work on sprite actors. Even if these events were to work, I still have to figure out how to find the tile index that was clicked on.
Two ideas I have for solutions:
Capture global mouse events and do the math to convert screen coordinates to tile index coordinates. I’ve done something like this, but the math is quite messy (especially for iso grids) and doesn’t quite work how I want it to. It also doesn’t help me if some other object like a menu now covers the tile map.
Instance new sprites at each tile location using Get Tile Center Position. Each sprite would have it’s own event code. I would not have to worry about any coordinate math, but I’d have to figure out how to handle X*Y sprites and their event graphs.
It’s better at this point to create your own tilemap in code out of actors but this can get performant heavy quick. I had to do this for that kinda control you’re looking for.
You create a single tile with a sprite component. You then provide it a function or custom event which can be called once you’ve traced for this tile specifically and then whatever else you need to mutate the sprite to your desires.
from there you make a TileMap generator which will create a tilemap of those actors.
Another more round about way of doing it is creating a Tmap of world coordinates. TMap | Unreal Engine Documentation
So tile maps allow you to get the four edges of the individual tile square as vector points.
You can build this into a tilemap BP no problem.
What you then do is trace down from your mouse, check that you hit the tilemap, record the point of impact, then provide that point of impact to your tilemap bp to check if it’s between the area between two vector points, then you’re at tile x,y (given back to you from the Tmap you made that contains two vector points.) and then you can do whatever you want with the tile at X,Y from the tile map.
Player Controller has a few helpful functions built in that let you deproject from your mouse pointer(Finger as well) which lets you trace into the world from the point of click into the world. you’d just have to get the end point of the Z correctly which doesn’t take much. You can create a relative system fairly easy with very simple/little math.
When using a tilemap and trying to get cursor/mouse/finger events working (and just collision in general) there are two things that you need to be sure are set up properly.
The tiles in the tileset which is used to make the tilemap need to have collisions set up on each tile. In the editor, open the tileset you are working with and make sure that each tile that you want to collide with has a collision boundary applied to it. In the image below you can see that I have set up collisions for the tiles on the top row as they are all highlighted in blue (shown by selecting “Colliding Tiles” in the toolbar). You can add collisions by selecting a tile and manually adding vertices in the viewport (blue window on the top right area of the image below) or by using the quick tools in the toolbar to add basic shapes.
After generating a tileset (especially if it is being edited at runtime in any way) you will need to rebuild the collision data for the tilemap. I’m using blueprints for this, so the solution is to just use the “Rebuild Collision” node for the tilemap you are trying to work with.
Once I did these two things my mouse and physics collisions worked perfectly.
I’m not super familiar with forum etiquette, so my bad if this necropost is taboo, but this is the only post I found relating to events/collision and tilemaps. I know the solution so I figured I’d post it here in case anyone else ended up on this old page looking for a solution.
[USER=“307619”]FUZZY COBALT[/USER] Is there any method you know of to know which tile from the tilemap you collided with? I wanted to draw my damage giving objects straight into the tilemap but I can’t seem to get a reference to anything but the whole tilemap when I receive the hit event.