Best way to show a token over a specific tag

I am working on building a placement game and I used this tutorial to help me build my grid and a token that shows where the build token is. The block in the video is representing where a player can place an object in my game.

I want this block to show up only when the mouse is over the play area. It currently shows up no matter where it is. Is the best (most efficient?) way to handle this to have the token show or hide itself if it’s colliding with the play area or is there a way to destroy/create it when it’s not in the play area and would that be better?

You can cast a line trace from the cursor to straight down to the ground and detect if the hit object is the one you’re looking for.

Here’s a tutorial on converting the cursor location into world space:

(Note that you should set the end location of the line trace to ( [Cursor X Axis], [Cursor Y Axis], -1000) to make it go straight down, being different from the tutorial. If your camera is facing straight down that is, if not, you should of course take the angle into consideration.)

If there are other objects on top of the surface we’re gonna be checking, you can make our line trace detect only certain objects by using a custom trace channel. Here’s a tutorial on it as well:

Finally, you can add an actor type tag to your surface and use the Actor Has Tag node to detect if the line trace hits it, or just use the display name. Though make sure to add an actor type tag for the tag one to work. And to check the hit actor, you can simply break the hit result of the line trace.

Hope this helps! :innocent:

1 Like

This is all super helpful. Thanks! The only remaining question I have is whether or not it’s better to destroy actors or hide them? So if the player moves their mouse off of the play field should I hide the actor (the box in the grid video) or destroy it?

1 Like

Of course hide! You definitely don’t want to unnecessarily destroy / spawn actors that frequenty :heart:

1 Like