I built a dynamic mouse cursor that changes its icon based on the objects it hovers. It’s working perfectly, but I’m a little worried about its performance.
Let me explain…
If you hover the mouse on an enemy, the mouse gets the shape of a gun target.
Then, if you are too far from the enemy, a red X is placed above the gun target to indicate that you can’t shoot. On the contrary, if you are close enough, to the side of the cursor you get the percentage that you hit the target when shooting.
Other than this, there a few other functions (think that I’m using 11 different icons for the mouse cursor)… so I need to make a cast to the player character.
And since you can possess multiple characters, I can’t just do the cast once and store the reference.
From what I know, there are 3 possible approaches:
Have all the functions on the mouse cursor (the solution I’m using at the moment). But having to put some casts in the widget’s binding doesn’t seem optimal to me.
Communicate between the blueprints (so, for example, when hovering an enemy, you call a function in the mouse cursor that change its icons). Not sure how expensive is this…
Having many mouse cursors, one for each icon. Then set a different cursor for the various actor classes you may hover.
Which do you think is the least expensive way of doing it?