Changing Mouse Texture on Mouse Over

I’ve been working on updating my mouse cursor when I mouse over different items in my game. So far I have everything working as I want it to, I was just wondering if there was a better way to do this.

This is placed on my actor and passes itself as a function to my Player Controller.

Controller.PNG

My controller than takes the first tag of the item we moused over and passes it to a function on my HUD…

That updates the texture of the mouse depending on what we moused over. It is also set to change it back to my default mouse after we stop mousing over the actor.

This works exactly as I intended it to. I’m just curious if there is a better way to do this. I was trying to come up with a way where I wouldn’t have to put the code on every actor in my game that I want to change the cursor for. If not well then feel free to use this, as it works! :stuck_out_tongue:

Instead of putting the code on every actor in the game, you could (in your player controller blueprint) “Single Line Trace by Channel” from your mouse cursor to the world. If your line trace hits an actor, try to cast it to an item, and then take its tag and pass it to your HUD blueprint.

Thanks for the advice! Alright so I got this working although I still think there could be a better way to do it.

So I was already using a hit result for the player movement (Top down style). So I just took the hit result from there and passed it into my custom event.

Which then checks if we hit something and updates our cursor correctly. I was then thinking about it and realized I never call the end cursor to switch it back to my default cursor, but it was working anyways. I realized this is because it’s probably hitting the ground which is something else and the switch case is just falling to the default cursor. Is there a different way I can do this so I just call my change methods when I actually mouse over something/stop mousing over something…rather than on tick?

Hello,
if you want you can check this tesla tutorial too to discover another way to do : [Tutorial] Basic Mouse Events - Community Content, Tools and Tutorials - Unreal Engine Forums

Fen,

Thanks for the reply. That is similar to how i did it in my original post where I would have to put code on every actor, which is something I’m trying to avoid. After the advice from Nylira I was able to get it working on just the Player Controller/HUD without the need to put any code on the actor. I will probably leave it this way until I can figure out something better, or until this causes a problem.