Dynamic Mouse Cursor

Hi guys,
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:

  1. 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.

  2. 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…

  3. 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?

Two questions first:

  • is that some RTS
  • do you do it in multiplayer

For now i assume both answers are yes.

For rts or squad based game you should do it bit differently.
Make player pawn that is only camera, control and hud.
All units should have AI that obeys player orders.
This makes a lot of things more clearly split in code.

For multiplayer all you need to worry is what you replicate, and replicating cursor behavior is not needed. So it does not matter much if you do line trace and cursor check once or 6 times.

some tips:

  • we slow humans do not see much difference between 1/60th second and 1/4 second delay for cursor to change. So do your cursor check every 10 or more frames. Best if you could cycle between checks, to not make all of them on single frame.
  • instead of casting use dispatchers, you hook and cast only once at begin play, then you call events to update info. Not sure if this is possible not knowing your setup.
1 Like

Thank you for the advice!

It’s a party-based RPG and it’s singleplayer.

Great idea. That would be way better than tick.

Is there any reason why you would use dispatchers over interfaces? I think both are viable. It’s just a matter of which is the best performing solution…

You worried about casting, dispatchers are solution to that. But yes it is matter of style more than anything else.

1 Like

Right :slight_smile: Thank you for your help, I’ll try to make it work with dispatchers.